Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ public class ApiConstants {
public static final String IP6_DNS1 = "ip6dns1";
public static final String IP6_DNS2 = "ip6dns2";
public static final String DOMAIN = "domain";
public static final String DOMAIN_DETAILS = "domaindetails";
public static final String DOMAIN_PATH = "domainpath";
public static final String DOMAIN_ID = "domainid";
public static final String DOMAIN__ID = "domainId";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.cloud.serializer.Param;

import java.util.Date;
import java.util.Map;

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

@SerializedName(ApiConstants.DOMAIN_DETAILS)
@Param(description = "details for the domain")
private Map<String, String> details;

public String getId() {
return this.id;
}
Expand Down Expand Up @@ -438,4 +443,8 @@ public void setVmRunning(Integer vmRunning) {
public void setResourceIconResponse(ResourceIconResponse icon) {
this.icon = icon;
}

public void setDetails(Map<String, String> details) {
this.details = details;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@
import java.util.List;
import java.util.Map;

import javax.inject.Inject;

import com.cloud.domain.DomainDetailVO;
import com.cloud.domain.DomainVO;
import com.cloud.utils.db.GenericDaoBase;
import com.cloud.utils.db.QueryBuilder;
import com.cloud.utils.db.SearchBuilder;
Expand All @@ -30,10 +33,16 @@
import org.apache.cloudstack.framework.config.ConfigKey;
import org.apache.cloudstack.framework.config.ConfigKey.Scope;
import org.apache.cloudstack.framework.config.ScopedConfigStorage;
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;

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

@Inject
protected DomainDao _domainDao;
@Inject
private ConfigurationDao _configDao;

protected DomainDetailsDaoImpl() {
domainSearch = createSearchBuilder();
domainSearch.and("domainId", domainSearch.entity().getDomainId(), Op.EQ);
Expand Down Expand Up @@ -98,7 +107,24 @@ public Scope getScope() {

@Override
public String getConfigValue(long id, ConfigKey<?> key) {
DomainDetailVO vo = findDetail(id, key.key());
DomainDetailVO vo = null;
String enableDomainSettingsForChildDomain = _configDao.getValue("enable.domain.settings.for.child.domain");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this string should probably come from some static final as now it is encoded twice (at least)

if (!Boolean.parseBoolean(enableDomainSettingsForChildDomain)) {
vo = findDetail(id, key.key());
return vo == null ? null : vo.getValue();
}
DomainVO domain = _domainDao.findById(id);
// if value is not configured in domain then check its parent domain till ROOT
while (domain != null) {
vo = findDetail(domain.getId(), key.key());
if (vo != null) {
break;
} else if (domain.getParent() != null) {
domain = _domainDao.findById(domain.getParent());
} else {
break;
}
}
return vo == null ? null : vo.getValue();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,40 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;

import javax.inject.Inject;

import org.apache.cloudstack.framework.config.ConfigKey;
import org.apache.cloudstack.framework.config.ConfigKey.Scope;
import org.apache.cloudstack.framework.config.ScopedConfigStorage;

import com.cloud.domain.DomainDetailVO;
import com.cloud.domain.DomainVO;
import com.cloud.domain.dao.DomainDetailsDao;
import com.cloud.domain.dao.DomainDao;
import com.cloud.user.dao.AccountDao;

import com.cloud.utils.db.GenericDaoBase;
import com.cloud.utils.db.QueryBuilder;
import com.cloud.utils.db.SearchBuilder;
import com.cloud.utils.db.SearchCriteria;
import com.cloud.utils.db.SearchCriteria.Op;
import com.cloud.utils.db.TransactionLegacy;
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;

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

@Inject
protected AccountDao _accountDao;
@Inject
protected DomainDao _domainDao;
@Inject
protected DomainDetailsDao _domainDetailsDao;
@Inject
private ConfigurationDao _configDao;

protected AccountDetailsDaoImpl() {
accountSearch = createSearchBuilder();
accountSearch.and("accountId", accountSearch.entity().getAccountId(), Op.EQ);
Expand Down Expand Up @@ -99,7 +117,39 @@ public Scope getScope() {

@Override
public String getConfigValue(long id, ConfigKey<?> key) {
// check if account level setting is configured
AccountDetailVO vo = findDetail(id, key.key());
return vo == null ? null : vo.getValue();
String value = vo == null ? null : vo.getValue();
if (value != null) {
return value;
}

// if account level setting is not configured then check if
// we can take value from domain
String enableAccountSettingsForDomain = _configDao.getValue("enable.account.settings.for.domain");
if (! Boolean.parseBoolean(enableAccountSettingsForDomain)) {
return null;
}

// check if we can traverse till ROOT domain to get the value
String enableDomainSettingsForChildDomain = _configDao.getValue("enable.domain.settings.for.child.domain");
if (Boolean.parseBoolean(enableDomainSettingsForChildDomain)) {
Optional<AccountVO> account = Optional.ofNullable(_accountDao.findById(id));
if (account.isPresent()) {
DomainVO domain = _domainDao.findById(account.get().getDomainId());
while (domain != null) {
DomainDetailVO domainVO = _domainDetailsDao.findDetail(domain.getId(), key.key());
if (domainVO != null) {
value = domainVO.getValue();
break;
} else if (domain.getParent() != null) {
domain = _domainDao.findById(domain.getParent());
} else {
break;
}
}
}
}
return value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,19 @@ public T valueIn(Long id) {
}
}

public T valueInDomain(Long domainId) {
if (domainId == null) {
return value();
}

String value = s_depot != null ? s_depot.getDomainScope(this).getConfigValue(domainId, this) : null;
if (value == null) {
return value();
} else {
return valueOf(value);
}
}

@SuppressWarnings("unchecked")
protected T valueOf(String value) {
Number multiplier = 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,16 @@ public ScopedConfigStorage findScopedConfigStorage(ConfigKey<?> config) {
throw new CloudRuntimeException("Unable to find config storage for this scope: " + config.scope() + " for " + config.key());
}

public ScopedConfigStorage getDomainScope(ConfigKey<?> config) {
for (ScopedConfigStorage storage : _scopedStorages) {
if (storage.getScope() == ConfigKey.Scope.Domain) {
return storage;
}
}

throw new CloudRuntimeException("Unable to find config storage for this scope: " + ConfigKey.Scope.Domain + " for " + config.key());
}

public List<ScopedConfigStorage> getScopedStorages() {
return _scopedStorages;
}
Expand Down
Loading