Added cleanup of affinitygroups when a VM is expunging and when the account is deleted.

This commit is contained in:
Prachi Damle 2013-04-03 16:53:57 -07:00
parent f786535571
commit d68856a2ff
2 changed files with 11 additions and 5 deletions

View File

@ -42,6 +42,7 @@ import org.apache.cloudstack.acl.ControlledEntity;
import org.apache.cloudstack.acl.RoleType;
import org.apache.cloudstack.acl.SecurityChecker;
import org.apache.cloudstack.acl.SecurityChecker.AccessType;
import org.apache.cloudstack.affinity.dao.AffinityGroupDao;
import org.apache.cloudstack.api.command.admin.account.UpdateAccountCmd;
import org.apache.cloudstack.api.command.admin.user.DeleteUserCmd;
import org.apache.cloudstack.api.command.admin.user.RegisterCmd;
@ -220,6 +221,8 @@ public class AccountManagerImpl extends ManagerBase implements AccountManager, M
@Inject
private AutoScaleManager _autoscaleMgr;
@Inject VolumeManager volumeMgr;
@Inject
private AffinityGroupDao _affinityGroupDao;
private List<UserAuthenticator> _userAuthenticators;
@ -237,11 +240,11 @@ public class AccountManagerImpl extends ManagerBase implements AccountManager, M
public List<UserAuthenticator> getUserAuthenticators() {
return _userAuthenticators;
}
public void setUserAuthenticators(List<UserAuthenticator> authenticators) {
_userAuthenticators = authenticators;
}
@Override
public boolean configure(final String name, final Map<String, Object> params) throws ConfigurationException {
_systemAccount = _accountDao.findById(AccountVO.ACCOUNT_ID_SYSTEM);
@ -606,6 +609,10 @@ public class AccountManagerImpl extends ManagerBase implements AccountManager, M
int numRemoved = _securityGroupDao.removeByAccountId(accountId);
s_logger.info("deleteAccount: Deleted " + numRemoved + " network groups for account " + accountId);
// Cleanup affinity groups
int numAGRemoved = _affinityGroupDao.removeByAccountId(accountId);
s_logger.info("deleteAccount: Deleted " + numAGRemoved + " affinity groups for account " + accountId);
// Delete all the networks
boolean networksDeleted = true;
s_logger.debug("Deleting networks for account " + account.getId());

View File

@ -240,6 +240,7 @@ public class AffinityGroupServiceImpl extends ManagerBase implements AffinityGro
@Override
public boolean configure(final String name, final Map<String, Object> params) throws ConfigurationException {
_name = name;
VirtualMachine.State.getStateMachine().registerListener(this);
return true;
}
@ -308,9 +309,7 @@ public class AffinityGroupServiceImpl extends ManagerBase implements AffinityGro
throw new InvalidParameterValueException("Unable to find affinity group by id " + affinityGroupId);
}
}
if (affinityGroupIds != null && !affinityGroupIds.isEmpty()) {
_affinityGroupVMMapDao.updateMap(vmId, affinityGroupIds);
}
_affinityGroupVMMapDao.updateMap(vmId, affinityGroupIds);
// APIResponseHelper will pull out the updated affinitygroups.
return vmInstance;