Skip to content

Commit c29cd9d

Browse files
Harikrishna Patnalakoushik-das
authored andcommitted
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
1 parent 7dceca5 commit c29cd9d

10 files changed

Lines changed: 87 additions & 16 deletions

File tree

api/src/com/cloud/deploy/DeploymentClusterPlanner.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,20 @@
2020

2121
import com.cloud.exception.InsufficientServerCapacityException;
2222
import com.cloud.vm.VirtualMachineProfile;
23+
import org.apache.cloudstack.framework.config.ConfigKey;
2324

2425
/**
2526
*/
2627
public interface DeploymentClusterPlanner extends DeploymentPlanner {
28+
29+
static final String ClusterCPUCapacityDisableThresholdCK = "cluster.cpu.allocated.capacity.disablethreshold";
30+
static final String ClusterMemoryCapacityDisableThresholdCK = "cluster.memory.allocated.capacity.disablethreshold";
31+
32+
static final ConfigKey<Float> ClusterCPUCapacityDisableThreshold = new ConfigKey<Float>(Float.class, ClusterCPUCapacityDisableThresholdCK, "Alert", "0.85",
33+
"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);
34+
static final ConfigKey<Float> ClusterMemoryCapacityDisableThreshold = new ConfigKey<Float>(Float.class, ClusterMemoryCapacityDisableThresholdCK, "Alert", "0.85",
35+
"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);
36+
2737
/**
2838
* This is called to determine list of possible clusters where a virtual
2939
* machine can be deployed.

framework/config/src/org/apache/cloudstack/framework/config/ConfigDepot.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,15 @@
1616
// under the License.
1717
package org.apache.cloudstack.framework.config;
1818

19+
import java.util.List;
20+
1921
/**
2022
* ConfigDepot is a repository of configurations.
2123
*
2224
*/
2325
public interface ConfigDepot {
2426

2527
ConfigKey<?> get(String paramName);
28+
29+
List<ConfigKey<?>> getConfigListByScope(String scope);
2630
}

framework/config/src/org/apache/cloudstack/framework/config/impl/ConfigDepotImpl.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,14 @@ public class ConfigDepotImpl implements ConfigDepot, ConfigDepotAdmin {
7676

7777
HashMap<String, Pair<String, ConfigKey<?>>> _allKeys = new HashMap<String, Pair<String, ConfigKey<?>>>(1007);
7878

79+
HashMap<ConfigKey.Scope, List<ConfigKey<?>>> _scopeLevelConfigsMap = new HashMap<ConfigKey.Scope, List<ConfigKey<?>>>();
80+
7981
public ConfigDepotImpl() {
8082
ConfigKey.init(this);
83+
_scopeLevelConfigsMap.put(ConfigKey.Scope.Zone, new ArrayList<ConfigKey<?>>());
84+
_scopeLevelConfigsMap.put(ConfigKey.Scope.Cluster, new ArrayList<ConfigKey<?>>());
85+
_scopeLevelConfigsMap.put(ConfigKey.Scope.StoragePool, new ArrayList<ConfigKey<?>>());
86+
_scopeLevelConfigsMap.put(ConfigKey.Scope.Account, new ArrayList<ConfigKey<?>>());
8187
}
8288

8389
@Override
@@ -108,7 +114,7 @@ protected void populateConfiguration(Date date, Configurable configurable) {
108114
": " + key.toString());
109115
}
110116
_allKeys.put(key.key(), new Pair<String, ConfigKey<?>>(configurable.getConfigComponentName(), key));
111-
117+
112118
ConfigurationVO vo = _configDao.findById(key.key());
113119
if (vo == null) {
114120
vo = new ConfigurationVO(configurable.getConfigComponentName(), key);
@@ -125,6 +131,10 @@ protected void populateConfiguration(Date date, Configurable configurable) {
125131
_configDao.persist(vo);
126132
}
127133
}
134+
if (key.scope() != ConfigKey.Scope.Global) {
135+
List<ConfigKey<?>> currentConfigs = _scopeLevelConfigsMap.get(key.scope());
136+
currentConfigs.add(key);
137+
}
128138
}
129139

130140
_configured.add(configurable);
@@ -172,4 +182,9 @@ public void setConfigurables(List<Configurable> configurables) {
172182
this._configurables = configurables;
173183
}
174184

185+
@Override
186+
public List<ConfigKey<?>> getConfigListByScope(String scope) {
187+
return _scopeLevelConfigsMap.get(ConfigKey.Scope.valueOf(scope));
188+
}
189+
175190
}

server/src/com/cloud/capacity/CapacityManagerImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -964,6 +964,6 @@ public String getConfigComponentName() {
964964

965965
@Override
966966
public ConfigKey<?>[] getConfigKeys() {
967-
return new ConfigKey<?>[] {CpuOverprovisioningFactor, MemOverprovisioningFactor};
967+
return new ConfigKey<?>[] {CpuOverprovisioningFactor, MemOverprovisioningFactor, StorageCapacityDisableThreshold, StorageOverprovisioningFactor, StorageAllocatedCapacityDisableThreshold};
968968
}
969969
}

server/src/com/cloud/configuration/Config.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,6 @@ public enum Config {
5757
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),
5858
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),
5959
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),
60-
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()),
61-
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()),
6260

6361

6462
// Storage

server/src/com/cloud/configuration/ConfigurationManagerImpl.java

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
import javax.inject.Inject;
3737
import javax.naming.ConfigurationException;
3838

39+
import com.cloud.deploy.DeploymentClusterPlanner;
40+
import org.apache.cloudstack.framework.config.ConfigDepot;
3941
import org.apache.log4j.Logger;
4042

4143
import org.apache.cloudstack.acl.SecurityChecker;
@@ -117,6 +119,7 @@
117119
import com.cloud.dc.dao.PodVlanMapDao;
118120
import com.cloud.dc.dao.VlanDao;
119121
import com.cloud.deploy.DataCenterDeployment;
122+
import com.cloud.deploy.DeploymentPlanner;
120123
import com.cloud.domain.Domain;
121124
import com.cloud.domain.DomainVO;
122125
import com.cloud.domain.dao.DomainDao;
@@ -215,6 +218,8 @@
215218
@Inject
216219
ConfigurationDao _configDao;
217220
@Inject
221+
ConfigDepot _configDepot;
222+
@Inject
218223
HostPodDao _podDao;
219224
@Inject
220225
AccountVlanMapDao _accountVlanMapDao;
@@ -372,8 +377,8 @@ private void weightBasedParametersForValidation() {
372377
weightBasedParametersForValidation.add(Config.LocalStorageCapacityThreshold.key());
373378
weightBasedParametersForValidation.add(CapacityManager.StorageAllocatedCapacityDisableThreshold.key());
374379
weightBasedParametersForValidation.add(CapacityManager.StorageCapacityDisableThreshold.key());
375-
weightBasedParametersForValidation.add(Config.CPUCapacityDisableThreshold.key());
376-
weightBasedParametersForValidation.add(Config.MemoryCapacityDisableThreshold.key());
380+
weightBasedParametersForValidation.add(DeploymentClusterPlanner.ClusterCPUCapacityDisableThreshold.key());
381+
weightBasedParametersForValidation.add(DeploymentClusterPlanner.ClusterMemoryCapacityDisableThreshold.key());
377382
weightBasedParametersForValidation.add(Config.AgentLoadThreshold.key());
378383
weightBasedParametersForValidation.add(Config.VmUserDispersionWeight.key());
379384

@@ -625,8 +630,17 @@ public Configuration updateConfiguration(UpdateCfgCmd cmd) throws InvalidParamet
625630
+ (((name.toLowerCase()).contains("password")) ? "*****" : (((value == null) ? "" : value))));
626631
// check if config value exists
627632
ConfigurationVO config = _configDao.findByName(name);
633+
String catergory = null;
634+
635+
// FIX ME - All configuration parameters are not moved from config.java to configKey
628636
if (config == null) {
629-
throw new InvalidParameterValueException("Config parameter with name " + name + " doesn't exist");
637+
if ( _configDepot.get(name) == null ) {
638+
s_logger.warn("Probably the component manager where configuration variable " + name + " is defined needs to implement Configurable interface");
639+
throw new InvalidParameterValueException("Config parameter with name " + name + " doesn't exist");
640+
}
641+
catergory = _configDepot.get(name).category();
642+
} else {
643+
catergory = config.getCategory();
630644
}
631645

632646
if (value == null) {
@@ -667,7 +681,7 @@ public Configuration updateConfiguration(UpdateCfgCmd cmd) throws InvalidParamet
667681
"cannot handle multiple IDs, provide only one ID corresponding to the scope");
668682
}
669683

670-
String updatedValue = updateConfiguration(userId, name, config.getCategory(), value, scope, id);
684+
String updatedValue = updateConfiguration(userId, name, catergory, value, scope, id);
671685
if ((value == null && updatedValue == null) || updatedValue.equalsIgnoreCase(value)) {
672686
return _configDao.findByName(name);
673687
} else {

server/src/com/cloud/deploy/FirstFitPlanner.java

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929

3030
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
3131
import org.apache.cloudstack.engine.subsystem.api.storage.StoragePoolAllocator;
32+
import org.apache.cloudstack.framework.config.ConfigKey;
33+
import org.apache.cloudstack.framework.config.Configurable;
3234
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
3335
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
3436

@@ -83,7 +85,7 @@
8385
import com.cloud.vm.dao.VMInstanceDao;
8486

8587
@Local(value=DeploymentPlanner.class)
86-
public class FirstFitPlanner extends PlannerBase implements DeploymentClusterPlanner {
88+
public class FirstFitPlanner extends PlannerBase implements DeploymentClusterPlanner, Configurable{
8789
private static final Logger s_logger = Logger.getLogger(FirstFitPlanner.class);
8890
@Inject protected HostDao _hostDao;
8991
@Inject protected DataCenterDao _dcDao;
@@ -246,11 +248,11 @@ private Map<Short, Float> getCapacityThresholdMap() {
246248
// if he changes these values
247249
Map<Short, Float> disableThresholdMap = new HashMap<Short, Float>();
248250

249-
String cpuDisableThresholdString = _configDao.getValue(Config.CPUCapacityDisableThreshold.key());
251+
String cpuDisableThresholdString = ClusterCPUCapacityDisableThreshold.value().toString();
250252
float cpuDisableThreshold = NumbersUtil.parseFloat(cpuDisableThresholdString, 0.85F);
251253
disableThresholdMap.put(Capacity.CAPACITY_TYPE_CPU, cpuDisableThreshold);
252254

253-
String memoryDisableThresholdString = _configDao.getValue(Config.MemoryCapacityDisableThreshold.key());
255+
String memoryDisableThresholdString = ClusterMemoryCapacityDisableThreshold.value().toString();
254256
float memoryDisableThreshold = NumbersUtil.parseFloat(memoryDisableThresholdString, 0.85F);
255257
disableThresholdMap.put(Capacity.CAPACITY_TYPE_MEMORY, memoryDisableThreshold);
256258

@@ -283,10 +285,10 @@ private void removeClustersCrossingThreshold(List<Long> clusterListForVmAllocati
283285
}
284286
if (capacity == Capacity.CAPACITY_TYPE_CPU) {
285287
clustersCrossingThreshold = _capacityDao.listClustersCrossingThreshold(capacity,
286-
plan.getDataCenterId(), Config.CPUCapacityDisableThreshold.key(), cpu_requested);
288+
plan.getDataCenterId(), ClusterCPUCapacityDisableThreshold.key(), cpu_requested);
287289
} else if (capacity == Capacity.CAPACITY_TYPE_MEMORY) {
288290
clustersCrossingThreshold = _capacityDao.listClustersCrossingThreshold(capacity,
289-
plan.getDataCenterId(), Config.MemoryCapacityDisableThreshold.key(), ram_requested);
291+
plan.getDataCenterId(), ClusterMemoryCapacityDisableThreshold.key(), ram_requested);
290292
}
291293

292294
if (clustersCrossingThreshold != null && clustersCrossingThreshold.size() != 0) {
@@ -522,4 +524,14 @@ public PlannerResourceUsage getResourceUsage(VirtualMachineProfile vmProfile,
522524
DeploymentPlan plan, ExcludeList avoid) throws InsufficientServerCapacityException {
523525
return PlannerResourceUsage.Shared;
524526
}
527+
528+
@Override
529+
public String getConfigComponentName() {
530+
return DeploymentClusterPlanner.class.getSimpleName();
531+
}
532+
533+
@Override
534+
public ConfigKey<?>[] getConfigKeys() {
535+
return new ConfigKey<?>[] {ClusterCPUCapacityDisableThreshold, ClusterMemoryCapacityDisableThreshold};
536+
}
525537
}

server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@
119119
import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService;
120120
import org.apache.cloudstack.framework.config.ConfigDepot;
121121
import org.apache.cloudstack.framework.config.ConfigKey;
122+
import org.apache.cloudstack.framework.config.Configurable;
122123
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
123124
import org.apache.cloudstack.framework.jobs.AsyncJobManager;
124125
import org.apache.cloudstack.framework.jobs.impl.AsyncJobVO;
@@ -137,7 +138,7 @@
137138
*/
138139
@Local(value = { VirtualNetworkApplianceManager.class, VirtualNetworkApplianceService.class })
139140
public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements VirtualNetworkApplianceManager, VirtualNetworkApplianceService,
140-
VirtualMachineGuru, Listener {
141+
VirtualMachineGuru, Listener, Configurable {
141142
private static final Logger s_logger = Logger.getLogger(VirtualNetworkApplianceManagerImpl.class);
142143

143144
@Inject
@@ -4097,4 +4098,14 @@ private List<Long> rebootRouters(List<DomainRouterVO> routers){
40974098
}
40984099
return jobIds;
40994100
}
4101+
4102+
@Override
4103+
public String getConfigComponentName() {
4104+
return VirtualNetworkApplianceManagerImpl.class.getSimpleName();
4105+
}
4106+
4107+
@Override
4108+
public ConfigKey<?>[] getConfigKeys() {
4109+
return new ConfigKey<?>[] {UseExternalDnsServers};
4110+
}
41004111
}

server/src/com/cloud/server/ConfigurationServerImpl.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444

4545
import org.apache.cloudstack.framework.config.ConfigDepot;
4646
import org.apache.cloudstack.framework.config.ConfigDepotAdmin;
47+
import org.apache.cloudstack.framework.config.ConfigKey;
4748
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
4849
import org.apache.cloudstack.framework.config.impl.ConfigurationVO;
4950
import org.apache.commons.codec.binary.Base64;
@@ -771,9 +772,9 @@ public void updateKeyPairs() {
771772
public List<ConfigurationVO> getConfigListByScope(String scope, Long resourceId) {
772773

773774
// Getting the list of parameters defined at the scope
774-
List<Config> configList = Config.getConfigListByScope(scope);
775+
List<ConfigKey<?>> configList = _configDepot.getConfigListByScope(scope);
775776
List<ConfigurationVO> configVOList = new ArrayList<ConfigurationVO>();
776-
for (Config param:configList){
777+
for (ConfigKey<?> param:configList){
777778
ConfigurationVO configVo = _configDao.findByName(param.toString());
778779
configVo.setValue(_configDepot.get(param.toString()).valueIn(resourceId).toString());
779780
configVOList.add(configVo);

server/test/org/apache/cloudstack/networkoffering/ChildTestConfiguration.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.apache.cloudstack.acl.SecurityChecker;
2525
import org.apache.cloudstack.affinity.AffinityGroupService;
2626
import org.apache.cloudstack.affinity.dao.AffinityGroupDao;
27+
import org.apache.cloudstack.framework.config.ConfigDepot;
2728
import org.apache.cloudstack.region.PortableIpDaoImpl;
2829
import org.apache.cloudstack.region.dao.RegionDaoImpl;
2930
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDaoImpl;
@@ -308,6 +309,11 @@ public ConfigurationDao configDao() {
308309
return Mockito.mock(ConfigurationDao.class);
309310
}
310311

312+
@Bean
313+
public ConfigDepot configDepot() {
314+
return Mockito.mock(ConfigDepot.class);
315+
}
316+
311317
@Bean
312318
public CallContext userContext() {
313319
return Mockito.mock(CallContext.class);

0 commit comments

Comments
 (0)