Skip to content

Commit dcc02e0

Browse files
raveningRakesh Venkatesh
andauthored
Enable account settings to be visible under domain settings (apache#4215)
* Enable account settings to be visible under domain settings All the account settings can't be configured under domain level settings right now. By default, if account setting is not configured then its value will be taken from global setting. Add a global setting "enable.account.settings.for.domain" so that if its enabled then all the account level settings will be visible under domain levelsettings also. If account level setting is configured then that value will be considered else it will take domain scope value. If domain scope value is not configured then it will pick it up from global setting. If domain level setting is not configured then by default the value will be taken from global setting Add another global setting "enable.domain.settings.for.child.domain" so that when its true, if a value for domain setting is not configured then its parent domain value is considered until it reaches ROOT domain. If no value is configured till ROOT domain then global setting value will be taken. Also display all the settings configured under the domain level in list domains api response * rename variables Co-authored-by: Rakesh Venkatesh <rakeshv@apache.org>
1 parent 9ef7355 commit dcc02e0

File tree

11 files changed

+731
-78
lines changed

11 files changed

+731
-78
lines changed

api/src/main/java/org/apache/cloudstack/api/ApiConstants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ public class ApiConstants {
137137
public static final String IP6_DNS1 = "ip6dns1";
138138
public static final String IP6_DNS2 = "ip6dns2";
139139
public static final String DOMAIN = "domain";
140+
public static final String DOMAIN_DETAILS = "domaindetails";
140141
public static final String DOMAIN_PATH = "domainpath";
141142
public static final String DOMAIN_ID = "domainid";
142143
public static final String DOMAIN__ID = "domainId";

api/src/main/java/org/apache/cloudstack/api/response/DomainResponse.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import com.cloud.serializer.Param;
2727

2828
import java.util.Date;
29+
import java.util.Map;
2930

3031
@EntityReference(value = Domain.class)
3132
public class DomainResponse extends BaseResponseWithAnnotations implements ResourceLimitAndCountResponse, SetResourceIconResponse {
@@ -179,6 +180,10 @@ public class DomainResponse extends BaseResponseWithAnnotations implements Resou
179180
@Param(description = "Base64 string representation of the resource icon", since = "4.16.0.0")
180181
ResourceIconResponse icon;
181182

183+
@SerializedName(ApiConstants.DOMAIN_DETAILS)
184+
@Param(description = "details for the domain")
185+
private Map<String, String> details;
186+
182187
public String getId() {
183188
return this.id;
184189
}
@@ -438,4 +443,8 @@ public void setVmRunning(Integer vmRunning) {
438443
public void setResourceIconResponse(ResourceIconResponse icon) {
439444
this.icon = icon;
440445
}
446+
447+
public void setDetails(Map<String, String> details) {
448+
this.details = details;
449+
}
441450
}

engine/schema/src/main/java/com/cloud/domain/dao/DomainDetailsDaoImpl.java

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@
2020
import java.util.List;
2121
import java.util.Map;
2222

23+
import javax.inject.Inject;
24+
2325
import com.cloud.domain.DomainDetailVO;
26+
import com.cloud.domain.DomainVO;
2427
import com.cloud.utils.db.GenericDaoBase;
2528
import com.cloud.utils.db.QueryBuilder;
2629
import com.cloud.utils.db.SearchBuilder;
@@ -30,10 +33,16 @@
3033
import org.apache.cloudstack.framework.config.ConfigKey;
3134
import org.apache.cloudstack.framework.config.ConfigKey.Scope;
3235
import org.apache.cloudstack.framework.config.ScopedConfigStorage;
36+
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
3337

3438
public class DomainDetailsDaoImpl extends GenericDaoBase<DomainDetailVO, Long> implements DomainDetailsDao, ScopedConfigStorage {
3539
protected final SearchBuilder<DomainDetailVO> domainSearch;
3640

41+
@Inject
42+
protected DomainDao _domainDao;
43+
@Inject
44+
private ConfigurationDao _configDao;
45+
3746
protected DomainDetailsDaoImpl() {
3847
domainSearch = createSearchBuilder();
3948
domainSearch.and("domainId", domainSearch.entity().getDomainId(), Op.EQ);
@@ -98,7 +107,24 @@ public Scope getScope() {
98107

99108
@Override
100109
public String getConfigValue(long id, ConfigKey<?> key) {
101-
DomainDetailVO vo = findDetail(id, key.key());
110+
DomainDetailVO vo = null;
111+
String enableDomainSettingsForChildDomain = _configDao.getValue("enable.domain.settings.for.child.domain");
112+
if (!Boolean.parseBoolean(enableDomainSettingsForChildDomain)) {
113+
vo = findDetail(id, key.key());
114+
return vo == null ? null : vo.getValue();
115+
}
116+
DomainVO domain = _domainDao.findById(id);
117+
// if value is not configured in domain then check its parent domain till ROOT
118+
while (domain != null) {
119+
vo = findDetail(domain.getId(), key.key());
120+
if (vo != null) {
121+
break;
122+
} else if (domain.getParent() != null) {
123+
domain = _domainDao.findById(domain.getParent());
124+
} else {
125+
break;
126+
}
127+
}
102128
return vo == null ? null : vo.getValue();
103129
}
104130
}

engine/schema/src/main/java/com/cloud/user/AccountDetailsDaoImpl.java

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,40 @@
1919
import java.util.HashMap;
2020
import java.util.List;
2121
import java.util.Map;
22+
import java.util.Optional;
2223

24+
import javax.inject.Inject;
2325

2426
import org.apache.cloudstack.framework.config.ConfigKey;
2527
import org.apache.cloudstack.framework.config.ConfigKey.Scope;
2628
import org.apache.cloudstack.framework.config.ScopedConfigStorage;
2729

30+
import com.cloud.domain.DomainDetailVO;
31+
import com.cloud.domain.DomainVO;
32+
import com.cloud.domain.dao.DomainDetailsDao;
33+
import com.cloud.domain.dao.DomainDao;
34+
import com.cloud.user.dao.AccountDao;
35+
2836
import com.cloud.utils.db.GenericDaoBase;
2937
import com.cloud.utils.db.QueryBuilder;
3038
import com.cloud.utils.db.SearchBuilder;
3139
import com.cloud.utils.db.SearchCriteria;
3240
import com.cloud.utils.db.SearchCriteria.Op;
3341
import com.cloud.utils.db.TransactionLegacy;
42+
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
3443

3544
public class AccountDetailsDaoImpl extends GenericDaoBase<AccountDetailVO, Long> implements AccountDetailsDao, ScopedConfigStorage {
3645
protected final SearchBuilder<AccountDetailVO> accountSearch;
3746

47+
@Inject
48+
protected AccountDao _accountDao;
49+
@Inject
50+
protected DomainDao _domainDao;
51+
@Inject
52+
protected DomainDetailsDao _domainDetailsDao;
53+
@Inject
54+
private ConfigurationDao _configDao;
55+
3856
protected AccountDetailsDaoImpl() {
3957
accountSearch = createSearchBuilder();
4058
accountSearch.and("accountId", accountSearch.entity().getAccountId(), Op.EQ);
@@ -99,7 +117,39 @@ public Scope getScope() {
99117

100118
@Override
101119
public String getConfigValue(long id, ConfigKey<?> key) {
120+
// check if account level setting is configured
102121
AccountDetailVO vo = findDetail(id, key.key());
103-
return vo == null ? null : vo.getValue();
122+
String value = vo == null ? null : vo.getValue();
123+
if (value != null) {
124+
return value;
125+
}
126+
127+
// if account level setting is not configured then check if
128+
// we can take value from domain
129+
String enableAccountSettingsForDomain = _configDao.getValue("enable.account.settings.for.domain");
130+
if (! Boolean.parseBoolean(enableAccountSettingsForDomain)) {
131+
return null;
132+
}
133+
134+
// check if we can traverse till ROOT domain to get the value
135+
String enableDomainSettingsForChildDomain = _configDao.getValue("enable.domain.settings.for.child.domain");
136+
if (Boolean.parseBoolean(enableDomainSettingsForChildDomain)) {
137+
Optional<AccountVO> account = Optional.ofNullable(_accountDao.findById(id));
138+
if (account.isPresent()) {
139+
DomainVO domain = _domainDao.findById(account.get().getDomainId());
140+
while (domain != null) {
141+
DomainDetailVO domainVO = _domainDetailsDao.findDetail(domain.getId(), key.key());
142+
if (domainVO != null) {
143+
value = domainVO.getValue();
144+
break;
145+
} else if (domain.getParent() != null) {
146+
domain = _domainDao.findById(domain.getParent());
147+
} else {
148+
break;
149+
}
150+
}
151+
}
152+
}
153+
return value;
104154
}
105155
}

framework/config/src/main/java/org/apache/cloudstack/framework/config/ConfigKey.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,19 @@ public T valueIn(Long id) {
160160
}
161161
}
162162

163+
public T valueInDomain(Long domainId) {
164+
if (domainId == null) {
165+
return value();
166+
}
167+
168+
String value = s_depot != null ? s_depot.getDomainScope(this).getConfigValue(domainId, this) : null;
169+
if (value == null) {
170+
return value();
171+
} else {
172+
return valueOf(value);
173+
}
174+
}
175+
163176
@SuppressWarnings("unchecked")
164177
protected T valueOf(String value) {
165178
Number multiplier = 1;

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,16 @@ public ScopedConfigStorage findScopedConfigStorage(ConfigKey<?> config) {
186186
throw new CloudRuntimeException("Unable to find config storage for this scope: " + config.scope() + " for " + config.key());
187187
}
188188

189+
public ScopedConfigStorage getDomainScope(ConfigKey<?> config) {
190+
for (ScopedConfigStorage storage : _scopedStorages) {
191+
if (storage.getScope() == ConfigKey.Scope.Domain) {
192+
return storage;
193+
}
194+
}
195+
196+
throw new CloudRuntimeException("Unable to find config storage for this scope: " + ConfigKey.Scope.Domain + " for " + config.key());
197+
}
198+
189199
public List<ScopedConfigStorage> getScopedStorages() {
190200
return _scopedStorages;
191201
}

0 commit comments

Comments
 (0)