mirror of https://github.com/apache/cloudstack.git
CS-16168 Cleaning up AutoScale resources when the account is deleted
Reviewed-by: vijay.venkatachalam@citrix.com
This commit is contained in:
parent
6c672886cb
commit
9c92f4537e
|
|
@ -13,4 +13,6 @@
|
|||
package com.cloud.network.as;
|
||||
|
||||
public interface AutoScaleManager extends AutoScaleService {
|
||||
|
||||
void cleanUpAutoScaleResources(Long accountId);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -91,8 +91,8 @@ import com.cloud.utils.db.SearchCriteria.Op;
|
|||
import com.cloud.utils.db.Transaction;
|
||||
import com.cloud.utils.net.NetUtils;
|
||||
|
||||
@Local(value = { AutoScaleService.class })
|
||||
public class AutoScaleManagerImpl<Type> implements AutoScaleService, Manager {
|
||||
@Local(value = { AutoScaleService.class, AutoScaleManager.class })
|
||||
public class AutoScaleManagerImpl<Type> implements AutoScaleManager, AutoScaleService, Manager {
|
||||
private static final Logger s_logger = Logger.getLogger(AutoScaleManagerImpl.class);
|
||||
|
||||
String _name;
|
||||
|
|
@ -1142,4 +1142,20 @@ public class AutoScaleManagerImpl<Type> implements AutoScaleService, Manager {
|
|||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,8 +12,10 @@
|
|||
// Automatically generated by addcopyright.py at 04/03/2012
|
||||
package com.cloud.network.as.dao;
|
||||
|
||||
|
||||
import com.cloud.network.as.AutoScalePolicyVO;
|
||||
import com.cloud.utils.db.GenericDao;
|
||||
|
||||
public interface AutoScalePolicyDao extends GenericDao<AutoScalePolicyVO, Long> {
|
||||
int removeByAccountId(long accountId);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,11 +12,21 @@
|
|||
// Automatically generated by addcopyright.py at 04/03/2012
|
||||
package com.cloud.network.as.dao;
|
||||
|
||||
|
||||
import javax.ejb.Local;
|
||||
|
||||
import com.cloud.network.as.AutoScalePolicyVO;
|
||||
import com.cloud.utils.db.GenericDaoBase;
|
||||
import com.cloud.utils.db.SearchCriteria;
|
||||
|
||||
@Local(value = { AutoScalePolicyDao.class })
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,4 +16,6 @@ import com.cloud.network.as.AutoScaleVmProfileVO;
|
|||
import com.cloud.utils.db.GenericDao;
|
||||
|
||||
public interface AutoScaleVmProfileDao extends GenericDao<AutoScaleVmProfileVO, Long> {
|
||||
|
||||
int removeByAccountId(long accountId);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,11 +12,21 @@
|
|||
// Automatically generated by addcopyright.py at 04/03/2012
|
||||
package com.cloud.network.as.dao;
|
||||
|
||||
|
||||
import javax.ejb.Local;
|
||||
|
||||
import com.cloud.network.as.AutoScaleVmProfileVO;
|
||||
import com.cloud.utils.db.GenericDaoBase;
|
||||
import com.cloud.utils.db.SearchCriteria;
|
||||
|
||||
@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,6 @@ public interface ConditionDao extends GenericDao<ConditionVO, Long> {
|
|||
|
||||
ConditionVO findByCounterId(long ctrId);
|
||||
|
||||
int removeByAccountId(long accountId);
|
||||
|
||||
}
|
||||
|
|
@ -17,6 +17,7 @@
|
|||
|
||||
package com.cloud.network.as.dao;
|
||||
|
||||
|
||||
import javax.ejb.Local;
|
||||
|
||||
import com.cloud.network.as.ConditionVO;
|
||||
|
|
@ -43,4 +44,12 @@ public class ConditionDaoImpl extends GenericDaoBase<ConditionVO, Long> implemen
|
|||
sc.setParameters("counterId", ctrId);
|
||||
return findOneBy(sc);
|
||||
}
|
||||
|
||||
public int removeByAccountId(long accountId) {
|
||||
SearchCriteria<ConditionVO> sc = createSearchCriteria();
|
||||
|
||||
sc.addAnd("accountId", SearchCriteria.Op.EQ, accountId);
|
||||
|
||||
return remove(sc);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -268,7 +268,7 @@ public class LoadBalancingRulesManagerImpl<Type> implements LoadBalancingRulesMa
|
|||
}
|
||||
AutoScaleVmProfile autoScaleVmProfile = _autoScaleVmProfileDao.findById(vmGroup.getProfileId());
|
||||
Long autoscaleUserId = autoScaleVmProfile.getAutoScaleUserId();
|
||||
User user = _userDao.findById(autoscaleUserId);
|
||||
User user = _userDao.findByIdIncludingRemoved(autoscaleUserId);
|
||||
String apiKey = user.getApiKey();
|
||||
String secretKey = user.getSecretKey();
|
||||
String csUrl = _configDao.getValue(Config.EndpointeUrl.key());
|
||||
|
|
|
|||
|
|
@ -73,6 +73,7 @@ import com.cloud.network.RemoteAccessVpnVO;
|
|||
import com.cloud.network.Site2SiteCustomerGatewayVO;
|
||||
import com.cloud.network.Site2SiteVpnConnectionVO;
|
||||
import com.cloud.network.VpnUserVO;
|
||||
import com.cloud.network.as.AutoScaleManager;
|
||||
import com.cloud.network.dao.IPAddressDao;
|
||||
import com.cloud.network.dao.NetworkDao;
|
||||
import com.cloud.network.dao.RemoteAccessVpnDao;
|
||||
|
|
@ -211,6 +212,8 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag
|
|||
@Inject
|
||||
private IPAddressDao _ipAddressDao;
|
||||
@Inject
|
||||
private AutoScaleManager _autoscaleMgr;
|
||||
@Inject
|
||||
private VpcManager _vpcMgr;
|
||||
@Inject
|
||||
private DomainRouterDao _routerDao;
|
||||
|
|
@ -613,12 +616,20 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag
|
|||
for (IpAddress ip : ipsToRelease) {
|
||||
s_logger.debug("Releasing ip " + ip + " as a part of account id=" + accountId + " cleanup");
|
||||
if (!_networkMgr.disassociatePublicIpAddress(ip.getId(), callerUserId, caller)) {
|
||||
s_logger.warn("Failed to release ip address " + ip + " as a part of account id=" + accountId + " clenaup");
|
||||
s_logger.warn("Failed to release ip address " + ip + " as a part of account id=" + accountId + " cleanup");
|
||||
accountCleanupNeeded = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 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 Site 2 Site VPN customer gateway
|
||||
s_logger.debug("Deleting site-to-site VPN customer gateways for account " + accountId);
|
||||
if (!_vpnMgr.deleteCustomerGatewayByAccount(accountId)) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue