mirror of
				https://github.com/apache/cloudstack.git
				synced 2025-10-26 08:42:29 +01:00 
			
		
		
		
	CS-16168:AutoScale- Deletion of Account doesn't delete the AutoScale LB rule
This commit is contained in:
		
							parent
							
								
									58db4d0d88
								
							
						
					
					
						commit
						d2155890cc
					
				| @ -17,4 +17,6 @@ | |||||||
| package com.cloud.network.as; | package com.cloud.network.as; | ||||||
| 
 | 
 | ||||||
| public interface AutoScaleManager extends AutoScaleService { | public interface AutoScaleManager extends AutoScaleService { | ||||||
|  | 
 | ||||||
|  |     void cleanUpAutoScaleResources(Long accountId); | ||||||
| } | } | ||||||
|  | |||||||
| @ -94,8 +94,8 @@ import com.cloud.utils.db.SearchCriteria.Op; | |||||||
| import com.cloud.utils.db.Transaction; | import com.cloud.utils.db.Transaction; | ||||||
| import com.cloud.utils.net.NetUtils; | import com.cloud.utils.net.NetUtils; | ||||||
| 
 | 
 | ||||||
| @Local(value = { AutoScaleService.class }) | @Local(value = { AutoScaleService.class, AutoScaleManager.class }) | ||||||
| public class AutoScaleManagerImpl<Type> implements AutoScaleService, Manager { | public class AutoScaleManagerImpl<Type> implements AutoScaleManager, AutoScaleService, Manager { | ||||||
|     private static final Logger s_logger = Logger.getLogger(AutoScaleManagerImpl.class); |     private static final Logger s_logger = Logger.getLogger(AutoScaleManagerImpl.class); | ||||||
| 
 | 
 | ||||||
|     String _name; |     String _name; | ||||||
| @ -1129,4 +1129,20 @@ public class AutoScaleManagerImpl<Type> implements AutoScaleService, Manager { | |||||||
|         return success; |         return success; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     public void cleanUpAutoScaleResources(Long accountId) { | ||||||
|  |         // cleans Autoscale VmProfiles, AutoScale Policies and Conditions belonging to an account | ||||||
|  |         int count = 0; | ||||||
|  |         count = _autoScaleVmProfileDao.removeByAccountId(accountId); | ||||||
|  |         if (count > 0) { | ||||||
|  |             s_logger.debug("Deleted " + count + " AutoScale Vm Profile for account Id: " + accountId); | ||||||
|  |         } | ||||||
|  |         count = _autoScalePolicyDao.removeByAccountId(accountId); | ||||||
|  |         if (count > 0) { | ||||||
|  |             s_logger.debug("Deleted " + count + " AutoScale Policies for account Id: " + accountId); | ||||||
|  |         } | ||||||
|  |         count = _conditionDao.removeByAccountId(accountId); | ||||||
|  |         if (count > 0) { | ||||||
|  |             s_logger.debug("Deleted " + count + " Conditions for account Id: " + accountId); | ||||||
|  |         } | ||||||
|  |     } | ||||||
| } | } | ||||||
|  | |||||||
| @ -20,4 +20,5 @@ import com.cloud.network.as.AutoScalePolicyVO; | |||||||
| import com.cloud.utils.db.GenericDao; | import com.cloud.utils.db.GenericDao; | ||||||
| 
 | 
 | ||||||
| public interface AutoScalePolicyDao extends GenericDao<AutoScalePolicyVO, Long> { | public interface AutoScalePolicyDao extends GenericDao<AutoScalePolicyVO, Long> { | ||||||
|  |     int removeByAccountId(long accountId); | ||||||
| } | } | ||||||
|  | |||||||
| @ -20,7 +20,16 @@ import javax.ejb.Local; | |||||||
| 
 | 
 | ||||||
| import com.cloud.network.as.AutoScalePolicyVO; | import com.cloud.network.as.AutoScalePolicyVO; | ||||||
| import com.cloud.utils.db.GenericDaoBase; | import com.cloud.utils.db.GenericDaoBase; | ||||||
|  | import com.cloud.utils.db.SearchCriteria; | ||||||
| 
 | 
 | ||||||
| @Local(value = { AutoScalePolicyDao.class }) | @Local(value = { AutoScalePolicyDao.class }) | ||||||
| public class AutoScalePolicyDaoImpl extends GenericDaoBase<AutoScalePolicyVO, Long>  implements AutoScalePolicyDao { | public class AutoScalePolicyDaoImpl extends GenericDaoBase<AutoScalePolicyVO, Long>  implements AutoScalePolicyDao { | ||||||
|  | 
 | ||||||
|  |     public int removeByAccountId(long accountId) { | ||||||
|  |         SearchCriteria<AutoScalePolicyVO> sc = createSearchCriteria(); | ||||||
|  | 
 | ||||||
|  |         sc.addAnd("accountId", SearchCriteria.Op.EQ, accountId); | ||||||
|  | 
 | ||||||
|  |         return remove(sc); | ||||||
|  |     } | ||||||
| } | } | ||||||
|  | |||||||
| @ -20,4 +20,6 @@ import com.cloud.network.as.AutoScaleVmProfileVO; | |||||||
| import com.cloud.utils.db.GenericDao; | import com.cloud.utils.db.GenericDao; | ||||||
| 
 | 
 | ||||||
| public interface AutoScaleVmProfileDao extends GenericDao<AutoScaleVmProfileVO, Long> { | public interface AutoScaleVmProfileDao extends GenericDao<AutoScaleVmProfileVO, Long> { | ||||||
|  | 
 | ||||||
|  |     int removeByAccountId(long accountId); | ||||||
| } | } | ||||||
|  | |||||||
| @ -20,7 +20,16 @@ import javax.ejb.Local; | |||||||
| 
 | 
 | ||||||
| import com.cloud.network.as.AutoScaleVmProfileVO; | import com.cloud.network.as.AutoScaleVmProfileVO; | ||||||
| import com.cloud.utils.db.GenericDaoBase; | import com.cloud.utils.db.GenericDaoBase; | ||||||
|  | import com.cloud.utils.db.SearchCriteria; | ||||||
| 
 | 
 | ||||||
| @Local(value = { AutoScaleVmProfileDao.class }) | @Local(value = { AutoScaleVmProfileDao.class }) | ||||||
| public class AutoScaleVmProfileDaoImpl extends GenericDaoBase<AutoScaleVmProfileVO, Long>  implements AutoScaleVmProfileDao { | public class AutoScaleVmProfileDaoImpl extends GenericDaoBase<AutoScaleVmProfileVO, Long>  implements AutoScaleVmProfileDao { | ||||||
|  | 
 | ||||||
|  |     @Override | ||||||
|  |     public int removeByAccountId(long accountId) { | ||||||
|  |         SearchCriteria<AutoScaleVmProfileVO> sc = createSearchCriteria(); | ||||||
|  |         sc.addAnd("accountId", SearchCriteria.Op.EQ, accountId); | ||||||
|  | 
 | ||||||
|  |         return remove(sc); | ||||||
|  |     } | ||||||
| } | } | ||||||
|  | |||||||
| @ -24,4 +24,5 @@ public interface ConditionDao extends GenericDao<ConditionVO, Long> { | |||||||
| 
 | 
 | ||||||
|     ConditionVO findByCounterId(long ctrId); |     ConditionVO findByCounterId(long ctrId); | ||||||
| 
 | 
 | ||||||
|  |     int removeByAccountId(long accountId); | ||||||
| } | } | ||||||
|  | |||||||
| @ -38,9 +38,16 @@ public class ConditionDaoImpl extends GenericDaoBase<ConditionVO, Long> implemen | |||||||
| 
 | 
 | ||||||
|     @Override |     @Override | ||||||
|     public ConditionVO findByCounterId(long ctrId) { |     public ConditionVO findByCounterId(long ctrId) { | ||||||
|         // TODO - may consider indexing counterId field in db-schema |  | ||||||
|         SearchCriteria<ConditionVO> sc = AllFieldsSearch.create(); |         SearchCriteria<ConditionVO> sc = AllFieldsSearch.create(); | ||||||
|         sc.setParameters("counterId", ctrId); |         sc.setParameters("counterId", ctrId); | ||||||
|         return findOneBy(sc); |         return findOneBy(sc); | ||||||
|     } |     } | ||||||
|  | 
 | ||||||
|  |     public int removeByAccountId(long accountId) { | ||||||
|  |         SearchCriteria<ConditionVO> sc = createSearchCriteria(); | ||||||
|  | 
 | ||||||
|  |         sc.addAnd("accountId", SearchCriteria.Op.EQ, accountId); | ||||||
|  | 
 | ||||||
|  |         return remove(sc); | ||||||
|  |     } | ||||||
| } | } | ||||||
|  | |||||||
| @ -259,7 +259,7 @@ public class LoadBalancingRulesManagerImpl<Type> implements LoadBalancingRulesMa | |||||||
|         } |         } | ||||||
|         AutoScaleVmProfile autoScaleVmProfile = _autoScaleVmProfileDao.findById(vmGroup.getProfileId()); |         AutoScaleVmProfile autoScaleVmProfile = _autoScaleVmProfileDao.findById(vmGroup.getProfileId()); | ||||||
|         Long autoscaleUserId = autoScaleVmProfile.getAutoScaleUserId(); |         Long autoscaleUserId = autoScaleVmProfile.getAutoScaleUserId(); | ||||||
|         User user = _userDao.findById(autoscaleUserId); |         User user = _userDao.findByIdIncludingRemoved(autoscaleUserId); | ||||||
|         String apiKey = user.getApiKey(); |         String apiKey = user.getApiKey(); | ||||||
|         String secretKey = user.getSecretKey(); |         String secretKey = user.getSecretKey(); | ||||||
|         String csUrl = _configDao.getValue(Config.EndpointeUrl.key()); |         String csUrl = _configDao.getValue(Config.EndpointeUrl.key()); | ||||||
|  | |||||||
| @ -75,6 +75,7 @@ import com.cloud.network.NetworkManager; | |||||||
| import com.cloud.network.NetworkVO; | import com.cloud.network.NetworkVO; | ||||||
| import com.cloud.network.RemoteAccessVpnVO; | import com.cloud.network.RemoteAccessVpnVO; | ||||||
| import com.cloud.network.VpnUserVO; | import com.cloud.network.VpnUserVO; | ||||||
|  | import com.cloud.network.as.AutoScaleManager; | ||||||
| import com.cloud.network.dao.IPAddressDao; | import com.cloud.network.dao.IPAddressDao; | ||||||
| import com.cloud.network.dao.NetworkDao; | import com.cloud.network.dao.NetworkDao; | ||||||
| import com.cloud.network.dao.RemoteAccessVpnDao; | import com.cloud.network.dao.RemoteAccessVpnDao; | ||||||
| @ -214,6 +215,8 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag | |||||||
|     private DomainRouterDao _routerDao; |     private DomainRouterDao _routerDao; | ||||||
|     @Inject |     @Inject | ||||||
|     Site2SiteVpnManager _vpnMgr; |     Site2SiteVpnManager _vpnMgr; | ||||||
|  |     @Inject | ||||||
|  |     private AutoScaleManager _autoscaleMgr; | ||||||
| 
 | 
 | ||||||
|     private Adapters<UserAuthenticator> _userAuthenticators; |     private Adapters<UserAuthenticator> _userAuthenticators; | ||||||
| 
 | 
 | ||||||
| @ -653,6 +656,14 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag | |||||||
|                 s_logger.warn("Fail to delete site-to-site VPN customer gateways for account " + accountId); |                 s_logger.warn("Fail to delete site-to-site VPN customer gateways for account " + accountId); | ||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
|  |             // Delete autoscale resources if any | ||||||
|  |             try { | ||||||
|  |                 _autoscaleMgr.cleanUpAutoScaleResources(accountId); | ||||||
|  |             } catch (CloudRuntimeException ex) { | ||||||
|  |                 s_logger.warn("Failed to cleanup AutoScale resources as a part of account id=" + accountId + " cleanup due to exception:", ex); | ||||||
|  |                 accountCleanupNeeded = true; | ||||||
|  |             } | ||||||
|  | 
 | ||||||
|             // delete account specific Virtual vlans (belong to system Public Network) - only when networks are cleaned |             // delete account specific Virtual vlans (belong to system Public Network) - only when networks are cleaned | ||||||
|             // up successfully |             // up successfully | ||||||
|             if (networksDeleted) { |             if (networksDeleted) { | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user