diff --git a/api/src/com/cloud/deploy/DeploymentClusterPlanner.java b/api/src/com/cloud/deploy/DeploymentClusterPlanner.java index ca73267e732..b4782239a35 100644 --- a/api/src/com/cloud/deploy/DeploymentClusterPlanner.java +++ b/api/src/com/cloud/deploy/DeploymentClusterPlanner.java @@ -20,10 +20,20 @@ import java.util.List; import com.cloud.exception.InsufficientServerCapacityException; import com.cloud.vm.VirtualMachineProfile; +import org.apache.cloudstack.framework.config.ConfigKey; /** */ public interface DeploymentClusterPlanner extends DeploymentPlanner { + + static final String ClusterCPUCapacityDisableThresholdCK = "cluster.cpu.allocated.capacity.disablethreshold"; + static final String ClusterMemoryCapacityDisableThresholdCK = "cluster.memory.allocated.capacity.disablethreshold"; + + static final ConfigKey ClusterCPUCapacityDisableThreshold = new ConfigKey(Float.class, ClusterCPUCapacityDisableThresholdCK, "Alert", "0.85", + "Percentage (as a value between 0 and 1) of cpu utilization above which allocators will disable using the cluster for low cpu available. Keep the corresponding notification threshold lower than this to be notified beforehand.", true, ConfigKey.Scope.Cluster, null); + static final ConfigKey ClusterMemoryCapacityDisableThreshold = new ConfigKey(Float.class, ClusterMemoryCapacityDisableThresholdCK, "Alert", "0.85", + "Percentage (as a value between 0 and 1) of memory utilization above which allocators will disable using the cluster for low memory available. Keep the corresponding notification threshold lower than this to be notified beforehand.", true, ConfigKey.Scope.Cluster, null); + /** * This is called to determine list of possible clusters where a virtual * machine can be deployed. diff --git a/framework/config/src/org/apache/cloudstack/framework/config/ConfigDepot.java b/framework/config/src/org/apache/cloudstack/framework/config/ConfigDepot.java index 2fd6efbb5da..22452b90417 100644 --- a/framework/config/src/org/apache/cloudstack/framework/config/ConfigDepot.java +++ b/framework/config/src/org/apache/cloudstack/framework/config/ConfigDepot.java @@ -16,6 +16,8 @@ // under the License. package org.apache.cloudstack.framework.config; +import java.util.List; + /** * ConfigDepot is a repository of configurations. * @@ -23,4 +25,6 @@ package org.apache.cloudstack.framework.config; public interface ConfigDepot { ConfigKey get(String paramName); + + List> getConfigListByScope(String scope); } diff --git a/framework/config/src/org/apache/cloudstack/framework/config/impl/ConfigDepotImpl.java b/framework/config/src/org/apache/cloudstack/framework/config/impl/ConfigDepotImpl.java index 254e6d20b06..305d286b580 100644 --- a/framework/config/src/org/apache/cloudstack/framework/config/impl/ConfigDepotImpl.java +++ b/framework/config/src/org/apache/cloudstack/framework/config/impl/ConfigDepotImpl.java @@ -76,8 +76,14 @@ public class ConfigDepotImpl implements ConfigDepot, ConfigDepotAdmin { HashMap>> _allKeys = new HashMap>>(1007); + HashMap>> _scopeLevelConfigsMap = new HashMap>>(); + public ConfigDepotImpl() { ConfigKey.init(this); + _scopeLevelConfigsMap.put(ConfigKey.Scope.Zone, new ArrayList>()); + _scopeLevelConfigsMap.put(ConfigKey.Scope.Cluster, new ArrayList>()); + _scopeLevelConfigsMap.put(ConfigKey.Scope.StoragePool, new ArrayList>()); + _scopeLevelConfigsMap.put(ConfigKey.Scope.Account, new ArrayList>()); } @Override @@ -108,7 +114,7 @@ public class ConfigDepotImpl implements ConfigDepot, ConfigDepotAdmin { ": " + key.toString()); } _allKeys.put(key.key(), new Pair>(configurable.getConfigComponentName(), key)); - + ConfigurationVO vo = _configDao.findById(key.key()); if (vo == null) { vo = new ConfigurationVO(configurable.getConfigComponentName(), key); @@ -125,6 +131,10 @@ public class ConfigDepotImpl implements ConfigDepot, ConfigDepotAdmin { _configDao.persist(vo); } } + if (key.scope() != ConfigKey.Scope.Global) { + List> currentConfigs = _scopeLevelConfigsMap.get(key.scope()); + currentConfigs.add(key); + } } _configured.add(configurable); @@ -172,4 +182,9 @@ public class ConfigDepotImpl implements ConfigDepot, ConfigDepotAdmin { this._configurables = configurables; } + @Override + public List> getConfigListByScope(String scope) { + return _scopeLevelConfigsMap.get(ConfigKey.Scope.valueOf(scope)); + } + } diff --git a/server/src/com/cloud/capacity/CapacityManagerImpl.java b/server/src/com/cloud/capacity/CapacityManagerImpl.java index a4c1bd2b590..854e27ab23c 100755 --- a/server/src/com/cloud/capacity/CapacityManagerImpl.java +++ b/server/src/com/cloud/capacity/CapacityManagerImpl.java @@ -1007,6 +1007,6 @@ public class CapacityManagerImpl extends ManagerBase implements CapacityManager, @Override public ConfigKey[] getConfigKeys() { - return new ConfigKey[] {CpuOverprovisioningFactor, MemOverprovisioningFactor}; + return new ConfigKey[] {CpuOverprovisioningFactor, MemOverprovisioningFactor, StorageCapacityDisableThreshold, StorageOverprovisioningFactor, StorageAllocatedCapacityDisableThreshold}; } } diff --git a/server/src/com/cloud/configuration/Config.java b/server/src/com/cloud/configuration/Config.java index bc805b7043e..fd26ff0495b 100755 --- a/server/src/com/cloud/configuration/Config.java +++ b/server/src/com/cloud/configuration/Config.java @@ -57,8 +57,6 @@ public enum Config { VlanCapacityThreshold("Alert", ManagementServer.class, Float.class, "zone.vlan.capacity.notificationthreshold", "0.75", "Percentage (as a value between 0 and 1) of Zone Vlan utilization above which alerts will be sent about low number of Zone Vlans.", null), DirectNetworkPublicIpCapacityThreshold("Alert", ManagementServer.class, Float.class, "zone.directnetwork.publicip.capacity.notificationthreshold", "0.75", "Percentage (as a value between 0 and 1) of Direct Network Public Ip Utilization above which alerts will be sent about low number of direct network public ips.", null), LocalStorageCapacityThreshold("Alert", ManagementServer.class, Float.class, "cluster.localStorage.capacity.notificationthreshold", "0.75", "Percentage (as a value between 0 and 1) of local storage utilization above which alerts will be sent about low local storage available.", null), - CPUCapacityDisableThreshold("Alert", ManagementServer.class, Float.class, "cluster.cpu.allocated.capacity.disablethreshold", "0.85", "Percentage (as a value between 0 and 1) of cpu utilization above which allocators will disable using the cluster for low cpu available. Keep the corresponding notification threshold lower than this to be notified beforehand.", null, ConfigKey.Scope.Cluster.toString()), - MemoryCapacityDisableThreshold("Alert", ManagementServer.class, Float.class, "cluster.memory.allocated.capacity.disablethreshold", "0.85", "Percentage (as a value between 0 and 1) of memory utilization above which allocators will disable using the cluster for low memory available. Keep the corresponding notification threshold lower than this to be notified beforehand.", null, ConfigKey.Scope.Cluster.toString()), // Storage diff --git a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java index 82256ca952e..21651ad3792 100755 --- a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java +++ b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java @@ -36,6 +36,8 @@ import javax.ejb.Local; import javax.inject.Inject; import javax.naming.ConfigurationException; +import com.cloud.deploy.DeploymentClusterPlanner; +import org.apache.cloudstack.framework.config.ConfigDepot; import org.apache.log4j.Logger; import org.apache.cloudstack.acl.SecurityChecker; @@ -117,6 +119,7 @@ import com.cloud.dc.dao.HostPodDao; import com.cloud.dc.dao.PodVlanMapDao; import com.cloud.dc.dao.VlanDao; import com.cloud.deploy.DataCenterDeployment; +import com.cloud.deploy.DeploymentPlanner; import com.cloud.domain.Domain; import com.cloud.domain.DomainVO; import com.cloud.domain.dao.DomainDao; @@ -215,6 +218,8 @@ ConfigurationManagerImpl extends ManagerBase implements ConfigurationManager, Co @Inject ConfigurationDao _configDao; @Inject + ConfigDepot _configDepot; + @Inject HostPodDao _podDao; @Inject AccountVlanMapDao _accountVlanMapDao; @@ -372,8 +377,8 @@ ConfigurationManagerImpl extends ManagerBase implements ConfigurationManager, Co weightBasedParametersForValidation.add(Config.LocalStorageCapacityThreshold.key()); weightBasedParametersForValidation.add(CapacityManager.StorageAllocatedCapacityDisableThreshold.key()); weightBasedParametersForValidation.add(CapacityManager.StorageCapacityDisableThreshold.key()); - weightBasedParametersForValidation.add(Config.CPUCapacityDisableThreshold.key()); - weightBasedParametersForValidation.add(Config.MemoryCapacityDisableThreshold.key()); + weightBasedParametersForValidation.add(DeploymentClusterPlanner.ClusterCPUCapacityDisableThreshold.key()); + weightBasedParametersForValidation.add(DeploymentClusterPlanner.ClusterMemoryCapacityDisableThreshold.key()); weightBasedParametersForValidation.add(Config.AgentLoadThreshold.key()); weightBasedParametersForValidation.add(Config.VmUserDispersionWeight.key()); @@ -625,8 +630,17 @@ ConfigurationManagerImpl extends ManagerBase implements ConfigurationManager, Co + (((name.toLowerCase()).contains("password")) ? "*****" : (((value == null) ? "" : value)))); // check if config value exists ConfigurationVO config = _configDao.findByName(name); + String catergory = null; + + // FIX ME - All configuration parameters are not moved from config.java to configKey if (config == null) { - throw new InvalidParameterValueException("Config parameter with name " + name + " doesn't exist"); + if ( _configDepot.get(name) == null ) { + s_logger.warn("Probably the component manager where configuration variable " + name + " is defined needs to implement Configurable interface"); + throw new InvalidParameterValueException("Config parameter with name " + name + " doesn't exist"); + } + catergory = _configDepot.get(name).category(); + } else { + catergory = config.getCategory(); } if (value == null) { @@ -667,7 +681,7 @@ ConfigurationManagerImpl extends ManagerBase implements ConfigurationManager, Co "cannot handle multiple IDs, provide only one ID corresponding to the scope"); } - String updatedValue = updateConfiguration(userId, name, config.getCategory(), value, scope, id); + String updatedValue = updateConfiguration(userId, name, catergory, value, scope, id); if ((value == null && updatedValue == null) || updatedValue.equalsIgnoreCase(value)) { return _configDao.findByName(name); } else { diff --git a/server/src/com/cloud/deploy/FirstFitPlanner.java b/server/src/com/cloud/deploy/FirstFitPlanner.java index 64b1124d6b8..3707d3d9065 100755 --- a/server/src/com/cloud/deploy/FirstFitPlanner.java +++ b/server/src/com/cloud/deploy/FirstFitPlanner.java @@ -29,6 +29,8 @@ import javax.naming.ConfigurationException; import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager; import org.apache.cloudstack.engine.subsystem.api.storage.StoragePoolAllocator; +import org.apache.cloudstack.framework.config.ConfigKey; +import org.apache.cloudstack.framework.config.Configurable; import org.apache.cloudstack.framework.config.dao.ConfigurationDao; import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao; @@ -83,7 +85,7 @@ import com.cloud.vm.dao.UserVmDao; import com.cloud.vm.dao.VMInstanceDao; @Local(value=DeploymentPlanner.class) -public class FirstFitPlanner extends PlannerBase implements DeploymentClusterPlanner { +public class FirstFitPlanner extends PlannerBase implements DeploymentClusterPlanner, Configurable{ private static final Logger s_logger = Logger.getLogger(FirstFitPlanner.class); @Inject protected HostDao _hostDao; @Inject protected DataCenterDao _dcDao; @@ -246,11 +248,11 @@ public class FirstFitPlanner extends PlannerBase implements DeploymentClusterPla // if he changes these values Map disableThresholdMap = new HashMap(); - String cpuDisableThresholdString = _configDao.getValue(Config.CPUCapacityDisableThreshold.key()); + String cpuDisableThresholdString = ClusterCPUCapacityDisableThreshold.value().toString(); float cpuDisableThreshold = NumbersUtil.parseFloat(cpuDisableThresholdString, 0.85F); disableThresholdMap.put(Capacity.CAPACITY_TYPE_CPU, cpuDisableThreshold); - String memoryDisableThresholdString = _configDao.getValue(Config.MemoryCapacityDisableThreshold.key()); + String memoryDisableThresholdString = ClusterMemoryCapacityDisableThreshold.value().toString(); float memoryDisableThreshold = NumbersUtil.parseFloat(memoryDisableThresholdString, 0.85F); disableThresholdMap.put(Capacity.CAPACITY_TYPE_MEMORY, memoryDisableThreshold); @@ -283,10 +285,10 @@ public class FirstFitPlanner extends PlannerBase implements DeploymentClusterPla } if (capacity == Capacity.CAPACITY_TYPE_CPU) { clustersCrossingThreshold = _capacityDao.listClustersCrossingThreshold(capacity, - plan.getDataCenterId(), Config.CPUCapacityDisableThreshold.key(), cpu_requested); + plan.getDataCenterId(), ClusterCPUCapacityDisableThreshold.key(), cpu_requested); } else if (capacity == Capacity.CAPACITY_TYPE_MEMORY) { clustersCrossingThreshold = _capacityDao.listClustersCrossingThreshold(capacity, - plan.getDataCenterId(), Config.MemoryCapacityDisableThreshold.key(), ram_requested); + plan.getDataCenterId(), ClusterMemoryCapacityDisableThreshold.key(), ram_requested); } if (clustersCrossingThreshold != null && clustersCrossingThreshold.size() != 0) { @@ -522,4 +524,14 @@ public class FirstFitPlanner extends PlannerBase implements DeploymentClusterPla DeploymentPlan plan, ExcludeList avoid) throws InsufficientServerCapacityException { return PlannerResourceUsage.Shared; } + + @Override + public String getConfigComponentName() { + return DeploymentClusterPlanner.class.getSimpleName(); + } + + @Override + public ConfigKey[] getConfigKeys() { + return new ConfigKey[] {ClusterCPUCapacityDisableThreshold, ClusterMemoryCapacityDisableThreshold}; + } } diff --git a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java index 5ac03b06105..3ba6cec453f 100755 --- a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java +++ b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java @@ -119,6 +119,7 @@ import org.apache.cloudstack.context.CallContext; import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService; import org.apache.cloudstack.framework.config.ConfigDepot; import org.apache.cloudstack.framework.config.ConfigKey; +import org.apache.cloudstack.framework.config.Configurable; import org.apache.cloudstack.framework.config.dao.ConfigurationDao; import org.apache.cloudstack.framework.jobs.AsyncJobManager; import org.apache.cloudstack.framework.jobs.impl.AsyncJobVO; @@ -137,7 +138,7 @@ import java.util.concurrent.*; */ @Local(value = { VirtualNetworkApplianceManager.class, VirtualNetworkApplianceService.class }) public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements VirtualNetworkApplianceManager, VirtualNetworkApplianceService, - VirtualMachineGuru, Listener { + VirtualMachineGuru, Listener, Configurable { private static final Logger s_logger = Logger.getLogger(VirtualNetworkApplianceManagerImpl.class); @Inject @@ -4097,4 +4098,14 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V } return jobIds; } + + @Override + public String getConfigComponentName() { + return VirtualNetworkApplianceManagerImpl.class.getSimpleName(); + } + + @Override + public ConfigKey[] getConfigKeys() { + return new ConfigKey[] {UseExternalDnsServers}; + } } diff --git a/server/src/com/cloud/server/ConfigurationServerImpl.java b/server/src/com/cloud/server/ConfigurationServerImpl.java index 8459adafb13..4020926640d 100755 --- a/server/src/com/cloud/server/ConfigurationServerImpl.java +++ b/server/src/com/cloud/server/ConfigurationServerImpl.java @@ -44,6 +44,7 @@ import javax.naming.ConfigurationException; import org.apache.cloudstack.framework.config.ConfigDepot; import org.apache.cloudstack.framework.config.ConfigDepotAdmin; +import org.apache.cloudstack.framework.config.ConfigKey; import org.apache.cloudstack.framework.config.dao.ConfigurationDao; import org.apache.cloudstack.framework.config.impl.ConfigurationVO; import org.apache.commons.codec.binary.Base64; @@ -771,9 +772,9 @@ public class ConfigurationServerImpl extends ManagerBase implements Configuratio public List getConfigListByScope(String scope, Long resourceId) { // Getting the list of parameters defined at the scope - List configList = Config.getConfigListByScope(scope); + List> configList = _configDepot.getConfigListByScope(scope); List configVOList = new ArrayList(); - for (Config param:configList){ + for (ConfigKey param:configList){ ConfigurationVO configVo = _configDao.findByName(param.toString()); configVo.setValue(_configDepot.get(param.toString()).valueIn(resourceId).toString()); configVOList.add(configVo); diff --git a/server/test/org/apache/cloudstack/networkoffering/ChildTestConfiguration.java b/server/test/org/apache/cloudstack/networkoffering/ChildTestConfiguration.java index d7ac3f7ce80..78a2336626d 100644 --- a/server/test/org/apache/cloudstack/networkoffering/ChildTestConfiguration.java +++ b/server/test/org/apache/cloudstack/networkoffering/ChildTestConfiguration.java @@ -24,6 +24,7 @@ import javax.inject.Inject; import org.apache.cloudstack.acl.SecurityChecker; import org.apache.cloudstack.affinity.AffinityGroupService; import org.apache.cloudstack.affinity.dao.AffinityGroupDao; +import org.apache.cloudstack.framework.config.ConfigDepot; import org.apache.cloudstack.region.PortableIpDaoImpl; import org.apache.cloudstack.region.dao.RegionDaoImpl; import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDaoImpl; @@ -308,6 +309,11 @@ public class ChildTestConfiguration { return Mockito.mock(ConfigurationDao.class); } + @Bean + public ConfigDepot configDepot() { + return Mockito.mock(ConfigDepot.class); + } + @Bean public CallContext userContext() { return Mockito.mock(CallContext.class);