@@ -445,20 +445,15 @@ public boolean lockAccount(long accountId) {
445445 @ Override
446446 public boolean deleteAccount (AccountVO account , long callerUserId , Account caller ) {
447447 long accountId = account .getId ();
448-
448+
449+ //delete the account record
449450 if (!_accountDao .remove (accountId )) {
450451 s_logger .error ("Unable to delete account " + accountId );
451452 return false ;
452453 }
453454
454- List <UserVO > users = _userDao .listByAccount (accountId );
455-
456- for (UserVO user : users ) {
457- _userDao .remove (user .getId ());
458- }
459-
460455 if (s_logger .isDebugEnabled ()) {
461- s_logger .debug ("Remove account " + accountId );
456+ s_logger .debug ("Removed account " + accountId );
462457 }
463458
464459 return cleanupAccount (account , callerUserId , caller );
@@ -468,8 +463,20 @@ public boolean deleteAccount(AccountVO account, long callerUserId, Account calle
468463 public boolean cleanupAccount (AccountVO account , long callerUserId , Account caller ) {
469464 long accountId = account .getId ();
470465 boolean accountCleanupNeeded = false ;
471-
466+
472467 try {
468+ //cleanup the users from the account
469+ List <UserVO > users = _userDao .listByAccount (accountId );
470+ for (UserVO user : users ) {
471+ if (!_userDao .remove (user .getId ())) {
472+ s_logger .error ("Unable to delete user: " + user + " as a part of account " + account + " cleanup" );
473+ accountCleanupNeeded = true ;
474+ }
475+ }
476+
477+ //delete the account from project accounts
478+ _projectAccountDao .removeAccountFromProjects (accountId );
479+
473480 // delete all vm groups belonging to accont
474481 List <InstanceGroupVO > groups = _vmGroupDao .listByAccountId (accountId );
475482 for (InstanceGroupVO group : groups ) {
@@ -582,7 +589,7 @@ public boolean cleanupAccount(AccountVO account, long callerUserId, Account call
582589 }
583590
584591 // delete account specific Virtual vlans (belong to system Public Network) - only when networks are cleaned
585- // up
592+ // up
586593 // successfully
587594 if (networksDeleted ) {
588595 if (!_configMgr .deleteAccountSpecificVirtualRanges (accountId )) {
@@ -1010,7 +1017,7 @@ public boolean deleteUserAccount(long accountId) {
10101017 }
10111018
10121019 // Account that manages project(s) can't be removed
1013- List <Long > managedProjectIds = _projectAccountDao .listAdministratedProjects (accountId );
1020+ List <Long > managedProjectIds = _projectAccountDao .listAdministratedProjectIds (accountId );
10141021 if (!managedProjectIds .isEmpty ()) {
10151022 StringBuilder projectIds = new StringBuilder ();
10161023 for (Long projectId : managedProjectIds ) {
0 commit comments