From 598503f094e4e06d2ebbbad9c72e4dc6feccb470 Mon Sep 17 00:00:00 2001 From: Murali Reddy Date: Fri, 8 Apr 2011 13:25:51 +0530 Subject: [PATCH] bug 9129:can't create vm if an instance limit is set at root domain pushing 2.2.4 fixes --- .../src/com/cloud/configuration/Config.java | 9 +++- server/src/com/cloud/test/DatabaseConfig.java | 6 --- .../com/cloud/user/AccountManagerImpl.java | 50 +++++++++++-------- setup/db/db/schema-222to224.sql | 7 ++- 4 files changed, 44 insertions(+), 28 deletions(-) diff --git a/server/src/com/cloud/configuration/Config.java b/server/src/com/cloud/configuration/Config.java index 0eaaf000369..dc9c9cd275f 100755 --- a/server/src/com/cloud/configuration/Config.java +++ b/server/src/com/cloud/configuration/Config.java @@ -226,8 +226,14 @@ public enum Config { DefaultPageSize("Advanced", ManagementServer.class, Long.class, "default.page.size", "500", "Default page size for API list* commands", null), - TaskCleanupRetryInterval("Advanced", ManagementServer.class, Integer.class, "task.cleanup.retry.interval", "600", "Time (in seconds) to wait before retrying cleanup of tasks if the cleanup failed previously. 0 means to never retry.", "Seconds"); + TaskCleanupRetryInterval("Advanced", ManagementServer.class, Integer.class, "task.cleanup.retry.interval", "600", "Time (in seconds) to wait before retrying cleanup of tasks if the cleanup failed previously. 0 means to never retry.", "Seconds"), + // Account Default Limits + DefaultMaxAccountUserVms("Account Defaults", ManagementServer.class, Long.class, "max.account.user.vms", "20", "The default maximum number of user VMs that can be deployed for an account", null), + DefaultMaxAccountPublicIPs("Account Defaults", ManagementServer.class, Long.class, "max.account.public.ips", "20", "The default maximum number of public IPs that can be consumed by an account", null), + DefaultMaxAccountTemplates("Account Defaults", ManagementServer.class, Long.class, "max.account.templates", "20", "The default maximum number of templates that can be deployed for an account", null), + DefaultMaxAccountSnapshots("Account Defaults", ManagementServer.class, Long.class, "max.account.snapshots", "20", "The default maximum number of snapshots that can be created for an account", null), + DefaultMaxAccountVolumes("Account Defaults", ManagementServer.class, Long.class, "max.account.volumes", "20", "The default maximum number of volumes that can be created for an account", null); private final String _category; private final Class _componentClass; @@ -250,6 +256,7 @@ public enum Config { _configs.put("Premium", new ArrayList()); _configs.put("Developer", new ArrayList()); _configs.put("Hidden", new ArrayList()); + _configs.put("Account Defaults", new ArrayList()); // Add values into HashMap for (Config c : Config.values()) { diff --git a/server/src/com/cloud/test/DatabaseConfig.java b/server/src/com/cloud/test/DatabaseConfig.java index f046973da8b..0649add389f 100755 --- a/server/src/com/cloud/test/DatabaseConfig.java +++ b/server/src/com/cloud/test/DatabaseConfig.java @@ -189,8 +189,6 @@ public class DatabaseConfig { s_configurationDescriptions.put("storage.capacity.threshold", "percentage (as a value between 0 and 1) of storage utilization above which alerts will be sent about low storage available"); s_configurationDescriptions.put("public.ip.capacity.threshold", "percentage (as a value between 0 and 1) of public IP address space utilization above which alerts will be sent"); s_configurationDescriptions.put("private.ip.capacity.threshold", "percentage (as a value between 0 and 1) of private IP address space utilization above which alerts will be sent"); - s_configurationDescriptions.put("max.account.user.vms", "the maximum number of user VMs that can be deployed for an account"); - s_configurationDescriptions.put("max.account.public.ips", "the maximum number of public IPs that can be reserved for an account"); s_configurationDescriptions.put("expunge.interval", "the interval to wait before running the expunge thread"); s_configurationDescriptions.put("network.throttling.rate", "default data transfer rate in megabits per second allowed per user"); s_configurationDescriptions.put("multicast.throttling.rate", "default multicast rate in megabits per second allowed"); @@ -234,8 +232,6 @@ public class DatabaseConfig { s_configurationComponents.put("public.ip.capacity.threshold", "management-server"); s_configurationComponents.put("private.ip.capacity.threshold", "management-server"); s_configurationComponents.put("capacity.check.period", "management-server"); - s_configurationComponents.put("max.account.user.vms", "management-server"); - s_configurationComponents.put("max.account.public.ips", "management-server"); s_configurationComponents.put("network.throttling.rate", "management-server"); s_configurationComponents.put("multicast.throttling.rate", "management-server"); s_configurationComponents.put("account.cleanup.interval", "management-server"); @@ -313,8 +309,6 @@ public class DatabaseConfig { s_defaultConfigurationValues.put("snapshot.test.months.per.year", "12"); s_defaultConfigurationValues.put("alert.wait", "1800"); s_defaultConfigurationValues.put("update.wait", "600"); - s_defaultConfigurationValues.put("max.account.user.vms", "20"); - s_defaultConfigurationValues.put("max.account.public.ips", "20"); s_defaultConfigurationValues.put("expunge.interval", "86400"); s_defaultConfigurationValues.put("extract.url.cleanup.interval", "120"); s_defaultConfigurationValues.put("instance.name", "VM"); diff --git a/server/src/com/cloud/user/AccountManagerImpl.java b/server/src/com/cloud/user/AccountManagerImpl.java index 0058207f04b..8051339bd7f 100755 --- a/server/src/com/cloud/user/AccountManagerImpl.java +++ b/server/src/com/cloud/user/AccountManagerImpl.java @@ -119,6 +119,7 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag private String _name; @Inject private AccountDao _accountDao; + @Inject ConfigurationDao _configDao; @Inject private DomainDao _domainDao; @Inject private ResourceLimitDao _resourceLimitDao; @Inject private ResourceCountDao _resourceCountDao; @@ -250,22 +251,33 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag public long findCorrectResourceLimit(AccountVO account, ResourceType type) { long max = -1; - // Check account ResourceLimitVO limit = _resourceLimitDao.findByAccountIdAndType(account.getId(), type); - + + // Check if limit is configured for account if (limit != null) { max = limit.getMax().longValue(); } else { - // If the account has an infinite limit, check the ROOT domain - Long domainId = account.getDomainId(); - while ((domainId != null) && (limit == null)) { - limit = _resourceLimitDao.findByDomainIdAndType(domainId, type); - DomainVO domain = _domainDao.findById(domainId); - domainId = domain.getParent(); - } - - if (limit != null) { - max = limit.getMax().longValue(); + // If the account has an no limit set, then return global default account limits + try { + switch (type) { + case public_ip: + max = Long.parseLong(_configDao.getValue(Config.DefaultMaxAccountPublicIPs.key())); + break; + case snapshot: + max = Long.parseLong(_configDao.getValue(Config.DefaultMaxAccountSnapshots.key())); + break; + case template: + max = Long.parseLong(_configDao.getValue(Config.DefaultMaxAccountTemplates.key())); + break; + case user_vm: + max = Long.parseLong(_configDao.getValue(Config.DefaultMaxAccountUserVms.key())); + break; + case volume: + max = Long.parseLong(_configDao.getValue(Config.DefaultMaxAccountVolumes.key())); + break; + } + } catch (NumberFormatException nfe) { + s_logger.error("Invalid value is set for the default account limit."); } } @@ -310,14 +322,12 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag if (m_resourceCountLock.lock(120)) { // 2 minutes try { - // Check account - ResourceLimitVO limit = _resourceLimitDao.findByAccountIdAndType(account.getId(), type); - - if (limit != null) { - long potentialCount = _resourceCountDao.getAccountCount(account.getId(), type) + numResources; - if (potentialCount > limit.getMax().longValue()) { - return true; - } + // Check account limits + AccountVO accountVo = _accountDao.findById(account.getAccountId()); + long accountLimit = findCorrectResourceLimit(accountVo, type); + long potentialCount = _resourceCountDao.getAccountCount(account.getId(), type) + numResources; + if (potentialCount > accountLimit) { + return true; } // check all domains in the account's domain hierarchy diff --git a/setup/db/db/schema-222to224.sql b/setup/db/db/schema-222to224.sql index 129c31511a9..6020d869631 100644 --- a/setup/db/db/schema-222to224.sql +++ b/setup/db/db/schema-222to224.sql @@ -114,7 +114,12 @@ INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Advanced','DEFAULT','management-server','vmware.private.vswitch',NULL,'Specify the vSwitch on host for private network'), ('Advanced','DEFAULT','management-server','vmware.public.vswitch',NULL,'Specify the vSwitch on host for public network'), ('Advanced','DEFAULT','management-server','vmware.service.console','Service Console','Specify the service console network name (ESX host only)'), -('Advanced','DEFAULT','AgentManager','xapiwait','600','Time (in seconds) to wait for XAPI to return'); +('Advanced','DEFAULT','AgentManager','xapiwait','600','Time (in seconds) to wait for XAPI to return'), +('Account Defaults','DEFAULT','management-server','max.account.user.vms','20','The default maximum number of user VMs that can be deployed for an account'), +('Account Defaults','DEFAULT','management-server','max.account.public.ips','20','The default maximum number of public IPs that can be consumed by an account'), +('Account Defaults','DEFAULT','management-server','max.account.templates','20','The default maximum number of templates that can be deployed for an account'), +('Account Defaults','DEFAULT','management-server','max.account.snapshots','20','The default maximum number of snapshots that can be created for an account'), +('Account Defaults','DEFAULT','management-server','max.account.volumes','20','The default maximum number of volumes that can be created for an account'); ALTER TABLE `cloud`.`op_dc_ip_address_alloc` CHANGE COLUMN `instance_id` `nic_id` bigint unsigned DEFAULT NULL; ALTER TABLE `cloud`.`op_dc_ip_address_alloc` ADD CONSTRAINT `fk_op_dc_ip_address_alloc__data_center_id` FOREIGN KEY (`data_center_id`) REFERENCES `data_center`(`id`) ON DELETE CASCADE;