bug 5576: remove network groups for account when account is deleted. Also ensure that ingress rules that reference these network groups are deleted

This commit is contained in:
Chiradeep Vittal 2011-01-06 16:55:17 -08:00
parent 7cb189962c
commit 05c72e4fe3
4 changed files with 13 additions and 2 deletions

View File

@ -28,5 +28,6 @@ public interface NetworkGroupDao extends GenericDao<NetworkGroupVO, Long> {
boolean isNameInUse(Long accountId, Long domainId, String name);
List<NetworkGroupVO> listAvailableGroups(Long accountId, Long domainId);
NetworkGroupVO findByAccountAndName(Long accountId, String name);
List<NetworkGroupVO> findByAccountAndNames(Long accountId, String... names);
List<NetworkGroupVO> findByAccountAndNames(Long accountId, String... names);
int removeByAccountId(long accountId);
}

View File

@ -125,5 +125,12 @@ public class NetworkGroupDaoImpl extends GenericDaoBase<NetworkGroupVO, Long> im
sc.setParameters("groupNames", (Object [])names);
return listActiveBy(sc);
}
@Override
public int removeByAccountId(long accountId) {
SearchCriteria sc = AccountIdSearch.create();
sc.setParameters("accountId", accountId);
return delete(sc);
}
}

View File

@ -1003,6 +1003,9 @@ public class ManagementServerImpl implements ManagementServer {
}
}
int numRemoved = _networkSecurityGroupDao.removeByAccountId(accountId);
s_logger.info("deleteAccount: Deleted " + numRemoved + " network groups for account " + accountId);
// Delete the account's VLANs
List<VlanVO> accountVlans = _vlanDao.listVlansForAccountByType(null, accountId, VlanType.DirectAttached);
boolean allVlansDeleted = true;

View File

@ -235,7 +235,7 @@ ALTER TABLE `cloud`.`network_group` ADD CONSTRAINT `fk_network_group__domain_id`
ALTER TABLE `cloud`.`network_group` ADD INDEX `i_network_group_name`(`name`);
ALTER TABLE `cloud`.`network_ingress_rule` ADD CONSTRAINT `fk_network_ingress_rule___network_group_id` FOREIGN KEY `fk_network_ingress_rule__network_group_id` (`network_group_id`) REFERENCES `network_group` (`id`) ON DELETE CASCADE;
ALTER TABLE `cloud`.`network_ingress_rule` ADD CONSTRAINT `fk_network_ingress_rule___allowed_network_id` FOREIGN KEY `fk_network_ingress_rule__allowed_network_id` (`allowed_network_id`) REFERENCES `network_group` (`id`);
ALTER TABLE `cloud`.`network_ingress_rule` ADD CONSTRAINT `fk_network_ingress_rule___allowed_network_id` FOREIGN KEY `fk_network_ingress_rule__allowed_network_id` (`allowed_network_id`) REFERENCES `network_group` (`id`) ON DELETE CASCADE;
ALTER TABLE `cloud`.`network_ingress_rule` ADD INDEX `i_network_ingress_rule_network_id`(`network_group_id`);
ALTER TABLE `cloud`.`network_ingress_rule` ADD INDEX `i_network_ingress_rule_allowed_network`(`allowed_network_id`);