mirror of https://github.com/apache/cloudstack.git
bug 13695: deleteAccount - remove account from projects as a part of account cleanup process
status 13695: resolved fixed Reviewed-by: Frank
This commit is contained in:
parent
67f074e867
commit
17349dfe12
|
|
@ -36,7 +36,9 @@ public interface ProjectAccountDao extends GenericDao<ProjectAccountVO, Long> {
|
|||
|
||||
List<Long> listPermittedAccountIds(long accountId);
|
||||
|
||||
List<Long> listAdministratedProjects(long adminAccountId);
|
||||
List<Long> listAdministratedProjectIds(long adminAccountId);
|
||||
|
||||
Long countByAccountIdAndRole(long accountId, ProjectAccount.Role role);
|
||||
|
||||
void removeAccountFromProjects(long accountId);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,6 +21,8 @@ import java.util.List;
|
|||
|
||||
import javax.ejb.Local;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.projects.ProjectAccount;
|
||||
import com.cloud.projects.ProjectAccountVO;
|
||||
import com.cloud.utils.db.GenericDaoBase;
|
||||
|
|
@ -36,6 +38,7 @@ public class ProjectAccountDaoImpl extends GenericDaoBase<ProjectAccountVO, Long
|
|||
final GenericSearchBuilder<ProjectAccountVO, Long> AdminSearch;
|
||||
final GenericSearchBuilder<ProjectAccountVO, Long> ProjectAccountSearch;
|
||||
final GenericSearchBuilder<ProjectAccountVO, Long> CountByRoleSearch;
|
||||
public static final Logger s_logger = Logger.getLogger(ProjectAccountDaoImpl.class.getName());
|
||||
|
||||
protected ProjectAccountDaoImpl() {
|
||||
AllFieldsSearch = createSearchBuilder();
|
||||
|
|
@ -124,7 +127,7 @@ public class ProjectAccountDaoImpl extends GenericDaoBase<ProjectAccountVO, Long
|
|||
}
|
||||
|
||||
@Override
|
||||
public List<Long> listAdministratedProjects(long adminAccountId) {
|
||||
public List<Long> listAdministratedProjectIds(long adminAccountId) {
|
||||
SearchCriteria<Long> sc = AdminSearch.create();
|
||||
sc.setParameters("role", ProjectAccount.Role.Admin);
|
||||
sc.setParameters("accountId", adminAccountId);
|
||||
|
|
@ -138,5 +141,16 @@ public class ProjectAccountDaoImpl extends GenericDaoBase<ProjectAccountVO, Long
|
|||
sc.setParameters("role", role);
|
||||
return customSearch(sc, null).get(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeAccountFromProjects(long accountId) {
|
||||
SearchCriteria<ProjectAccountVO> sc = AllFieldsSearch.create();
|
||||
sc.setParameters("accountId", accountId);
|
||||
|
||||
int rowsRemoved = remove(sc);
|
||||
if (rowsRemoved > 0) {
|
||||
s_logger.debug("Removed account id=" + accountId + " from " + rowsRemoved + " projects");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -445,20 +445,15 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag
|
|||
@Override
|
||||
public boolean deleteAccount(AccountVO account, long callerUserId, Account caller) {
|
||||
long accountId = account.getId();
|
||||
|
||||
|
||||
//delete the account record
|
||||
if (!_accountDao.remove(accountId)) {
|
||||
s_logger.error("Unable to delete account " + accountId);
|
||||
return false;
|
||||
}
|
||||
|
||||
List<UserVO> users = _userDao.listByAccount(accountId);
|
||||
|
||||
for (UserVO user : users) {
|
||||
_userDao.remove(user.getId());
|
||||
}
|
||||
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("Remove account " + accountId);
|
||||
s_logger.debug("Removed account " + accountId);
|
||||
}
|
||||
|
||||
return cleanupAccount(account, callerUserId, caller);
|
||||
|
|
@ -468,8 +463,20 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag
|
|||
public boolean cleanupAccount(AccountVO account, long callerUserId, Account caller) {
|
||||
long accountId = account.getId();
|
||||
boolean accountCleanupNeeded = false;
|
||||
|
||||
|
||||
try {
|
||||
//cleanup the users from the account
|
||||
List<UserVO> users = _userDao.listByAccount(accountId);
|
||||
for (UserVO user : users) {
|
||||
if (!_userDao.remove(user.getId())) {
|
||||
s_logger.error("Unable to delete user: " + user + " as a part of account " + account + " cleanup");
|
||||
accountCleanupNeeded = true;
|
||||
}
|
||||
}
|
||||
|
||||
//delete the account from project accounts
|
||||
_projectAccountDao.removeAccountFromProjects(accountId);
|
||||
|
||||
// delete all vm groups belonging to accont
|
||||
List<InstanceGroupVO> groups = _vmGroupDao.listByAccountId(accountId);
|
||||
for (InstanceGroupVO group : groups) {
|
||||
|
|
@ -582,7 +589,7 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag
|
|||
}
|
||||
|
||||
// delete account specific Virtual vlans (belong to system Public Network) - only when networks are cleaned
|
||||
// up
|
||||
// up
|
||||
// successfully
|
||||
if (networksDeleted) {
|
||||
if (!_configMgr.deleteAccountSpecificVirtualRanges(accountId)) {
|
||||
|
|
@ -1010,7 +1017,7 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag
|
|||
}
|
||||
|
||||
// Account that manages project(s) can't be removed
|
||||
List<Long> managedProjectIds = _projectAccountDao.listAdministratedProjects(accountId);
|
||||
List<Long> managedProjectIds = _projectAccountDao.listAdministratedProjectIds(accountId);
|
||||
if (!managedProjectIds.isEmpty()) {
|
||||
StringBuilder projectIds = new StringBuilder();
|
||||
for (Long projectId : managedProjectIds) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue