CLOUDSTACK-4835: Update global configuration test cases failed in master Changes made in update/list configuration API to use ConfigDepot

CLOUDSTACK-4169: Scoped configuraion parameters logic moved to ConfigDepot

CLOUDSTACK-5163: missing parameters in configuration table
This commit is contained in:
Harikrishna Patnala 2013-11-15 12:16:51 +05:30 committed by Koushik Das
parent 7dceca5995
commit c29cd9d3c7
10 changed files with 87 additions and 16 deletions

View File

@ -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<Float> ClusterCPUCapacityDisableThreshold = new ConfigKey<Float>(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<Float> ClusterMemoryCapacityDisableThreshold = new ConfigKey<Float>(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.

View File

@ -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<ConfigKey<?>> getConfigListByScope(String scope);
}

View File

@ -76,8 +76,14 @@ public class ConfigDepotImpl implements ConfigDepot, ConfigDepotAdmin {
HashMap<String, Pair<String, ConfigKey<?>>> _allKeys = new HashMap<String, Pair<String, ConfigKey<?>>>(1007);
HashMap<ConfigKey.Scope, List<ConfigKey<?>>> _scopeLevelConfigsMap = new HashMap<ConfigKey.Scope, List<ConfigKey<?>>>();
public ConfigDepotImpl() {
ConfigKey.init(this);
_scopeLevelConfigsMap.put(ConfigKey.Scope.Zone, new ArrayList<ConfigKey<?>>());
_scopeLevelConfigsMap.put(ConfigKey.Scope.Cluster, new ArrayList<ConfigKey<?>>());
_scopeLevelConfigsMap.put(ConfigKey.Scope.StoragePool, new ArrayList<ConfigKey<?>>());
_scopeLevelConfigsMap.put(ConfigKey.Scope.Account, new ArrayList<ConfigKey<?>>());
}
@Override
@ -108,7 +114,7 @@ public class ConfigDepotImpl implements ConfigDepot, ConfigDepotAdmin {
": " + key.toString());
}
_allKeys.put(key.key(), new Pair<String, ConfigKey<?>>(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<ConfigKey<?>> 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<ConfigKey<?>> getConfigListByScope(String scope) {
return _scopeLevelConfigsMap.get(ConfigKey.Scope.valueOf(scope));
}
}

View File

@ -964,6 +964,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};
}
}

View File

@ -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

View File

@ -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 {

View File

@ -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<Short, Float> disableThresholdMap = new HashMap<Short, Float>();
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};
}
}

View File

@ -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};
}
}

View File

@ -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<ConfigurationVO> getConfigListByScope(String scope, Long resourceId) {
// Getting the list of parameters defined at the scope
List<Config> configList = Config.getConfigListByScope(scope);
List<ConfigKey<?>> configList = _configDepot.getConfigListByScope(scope);
List<ConfigurationVO> configVOList = new ArrayList<ConfigurationVO>();
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);

View File

@ -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);