Skip to content

Commit bae5be7

Browse files
Harikrishna Patnalakoushik-das
authored andcommitted
CLOUDSTACK-5551: Search not working for Configuration parameters in (Account/zone/cluster/storage) settings page
Added filters while listing scoped configuration parameters. Fixed: Some parameters are missing from UI settings tab because of missing scope entry in configuration table.
1 parent b763e49 commit bae5be7

5 files changed

Lines changed: 40 additions & 22 deletions

File tree

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

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

19-
import java.util.List;
19+
import java.util.Set;
2020

2121
/**
2222
* ConfigDepot is a repository of configurations.
@@ -26,5 +26,5 @@ public interface ConfigDepot {
2626

2727
ConfigKey<?> get(String paramName);
2828

29-
List<ConfigKey<?>> getConfigListByScope(String scope);
29+
Set<ConfigKey<?>> getConfigListByScope(String scope);
3030
}

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

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +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<?>>>();
79+
HashMap<ConfigKey.Scope, Set<ConfigKey<?>>> _scopeLevelConfigsMap = new HashMap<ConfigKey.Scope, Set<ConfigKey<?>>>();
8080

8181
public ConfigDepotImpl() {
8282
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<?>>());
83+
_scopeLevelConfigsMap.put(ConfigKey.Scope.Zone, new HashSet<ConfigKey<?>>());
84+
_scopeLevelConfigsMap.put(ConfigKey.Scope.Cluster, new HashSet<ConfigKey<?>>());
85+
_scopeLevelConfigsMap.put(ConfigKey.Scope.StoragePool, new HashSet<ConfigKey<?>>());
86+
_scopeLevelConfigsMap.put(ConfigKey.Scope.Account, new HashSet<ConfigKey<?>>());
8787
}
8888

8989
@Override
@@ -123,16 +123,18 @@ protected void populateConfiguration(Date date, Configurable configurable) {
123123
} else {
124124
if (vo.isDynamic() != key.isDynamic() ||
125125
!ObjectUtils.equals(vo.getDescription(), key.description()) ||
126-
!ObjectUtils.equals(vo.getDefaultValue(), key.defaultValue())) {
126+
!ObjectUtils.equals(vo.getDefaultValue(), key.defaultValue()) ||
127+
!ObjectUtils.equals(vo.getScope(), key.scope().toString())) {
127128
vo.setDynamic(key.isDynamic());
128129
vo.setDescription(key.description());
129130
vo.setDefaultValue(key.defaultValue());
131+
vo.setScope(key.scope().toString());
130132
vo.setUpdated(date);
131133
_configDao.persist(vo);
132134
}
133135
}
134-
if (key.scope() != ConfigKey.Scope.Global) {
135-
List<ConfigKey<?>> currentConfigs = _scopeLevelConfigsMap.get(key.scope());
136+
if ((key.scope() != null) && (key.scope() != ConfigKey.Scope.Global)) {
137+
Set<ConfigKey<?>> currentConfigs = _scopeLevelConfigsMap.get(key.scope());
136138
currentConfigs.add(key);
137139
}
138140
}
@@ -183,7 +185,7 @@ public void setConfigurables(List<Configurable> configurables) {
183185
}
184186

185187
@Override
186-
public List<ConfigKey<?>> getConfigListByScope(String scope) {
188+
public Set<ConfigKey<?>> getConfigListByScope(String scope) {
187189
return _scopeLevelConfigsMap.get(ConfigKey.Scope.valueOf(scope));
188190
}
189191

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import java.util.ArrayList;
3333
import java.util.HashMap;
3434
import java.util.List;
35+
import java.util.Set;
3536
import java.util.Map;
3637
import java.util.Properties;
3738
import java.util.UUID;
@@ -772,7 +773,7 @@ public void updateKeyPairs() {
772773
public List<ConfigurationVO> getConfigListByScope(String scope, Long resourceId) {
773774

774775
// Getting the list of parameters defined at the scope
775-
List<ConfigKey<?>> configList = _configDepot.getConfigListByScope(scope);
776+
Set<ConfigKey<?>> configList = _configDepot.getConfigListByScope(scope);
776777
List<ConfigurationVO> configVOList = new ArrayList<ConfigurationVO>();
777778
for (ConfigKey<?> param:configList){
778779
ConfigurationVO configVo = _configDao.findByName(param.toString());

‎server/src/com/cloud/server/ManagementServerImpl.java‎

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import javax.inject.Inject;
4343
import javax.naming.ConfigurationException;
4444

45+
import org.apache.cloudstack.framework.config.ConfigDepot;
4546
import org.apache.commons.codec.binary.Base64;
4647
import org.apache.log4j.Logger;
4748

@@ -713,6 +714,8 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
713714
@Inject
714715
ConfigurationServer _configServer;
715716
@Inject
717+
ConfigDepot _configDepot;
718+
@Inject
716719
UserVmManager _userVmMgr;
717720
@Inject
718721
VolumeDataFactory _volFactory;
@@ -1680,15 +1683,6 @@ public Pair<List<? extends Configuration>, Integer> searchForConfigurations(List
16801683
throw new InvalidParameterValueException("cannot handle multiple IDs, provide only one ID corresponding to the scope");
16811684
}
16821685

1683-
if (scope != null && !scope.isEmpty()) {
1684-
// getting the list of parameters at requested scope
1685-
if (id == null) {
1686-
throw new InvalidParameterValueException("Invalid id null, id is needed corresponding to the scope");
1687-
}
1688-
List<ConfigurationVO> configList = _configServer.getConfigListByScope(scope, id);
1689-
return new Pair<List<? extends Configuration>, Integer>(configList, configList.size());
1690-
}
1691-
16921686
if (keyword != null) {
16931687
SearchCriteria<ConfigurationVO> ssc = _configDao.createSearchCriteria();
16941688
ssc.addOr("name", SearchCriteria.Op.LIKE, "%" + keyword + "%");
@@ -1712,7 +1706,28 @@ public Pair<List<? extends Configuration>, Integer> searchForConfigurations(List
17121706
// hidden configurations are not displayed using the search API
17131707
sc.addAnd("category", SearchCriteria.Op.NEQ, "Hidden");
17141708

1709+
if (scope != null && !scope.isEmpty()) {
1710+
// getting the list of parameters at requested scope
1711+
if (id == null) {
1712+
throw new InvalidParameterValueException("Invalid id null, id is needed corresponding to the scope");
1713+
}
1714+
sc.addAnd("scope", SearchCriteria.Op.EQ, scope);
1715+
}
1716+
17151717
Pair<List<ConfigurationVO>, Integer> result = _configDao.searchAndCount(sc, searchFilter);
1718+
1719+
if (scope != null && !scope.isEmpty()) {
1720+
// Populate values corresponding the resource id
1721+
List<ConfigurationVO> configVOList = new ArrayList<ConfigurationVO>();
1722+
for (ConfigurationVO param: result.first()){
1723+
ConfigurationVO configVo = _configDao.findByName(param.getName());
1724+
configVo.setValue(_configDepot.get(param.getName()).valueIn(id).toString());
1725+
configVOList.add(configVo);
1726+
}
1727+
1728+
return new Pair<List<? extends Configuration>, Integer>(configVOList, configVOList.size());
1729+
}
1730+
17161731
return new Pair<List<? extends Configuration>, Integer>(result.first(), result.second());
17171732
}
17181733

‎server/src/com/cloud/vm/UserVmManager.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
public interface UserVmManager extends UserVmService {
4747
static final String EnableDynamicallyScaleVmCK = "enable.dynamic.scale.vm";
4848
static final ConfigKey<Boolean> EnableDynamicallyScaleVm = new ConfigKey<Boolean>("Advanced", Boolean.class, EnableDynamicallyScaleVmCK, "false",
49-
"Enables/Diables dynamically scaling a vm", true, ConfigKey.Scope.Zone);
49+
"Enables/Disables dynamically scaling a vm", true, ConfigKey.Scope.Zone);
5050

5151

5252
static final int MAX_USER_DATA_LENGTH_BYTES = 2048;

0 commit comments

Comments
 (0)