Search in sources :

Example 1 with DomainDetailVO

use of com.cloud.domain.DomainDetailVO in project cloudstack by apache.

the class ConfigurationManagerImpl method resetConfiguration.

@Override
@ActionEvent(eventType = EventTypes.EVENT_CONFIGURATION_VALUE_EDIT, eventDescription = "resetting configuration")
public Pair<Configuration, String> resetConfiguration(final ResetCfgCmd cmd) throws InvalidParameterValueException {
    final Long userId = CallContext.current().getCallingUserId();
    final String name = cmd.getCfgName();
    final Long zoneId = cmd.getZoneId();
    final Long clusterId = cmd.getClusterId();
    final Long storagepoolId = cmd.getStoragepoolId();
    final Long accountId = cmd.getAccountId();
    final Long domainId = cmd.getDomainId();
    final Long imageStoreId = cmd.getImageStoreId();
    Optional optionalValue;
    final ConfigKey<?> configKey = _configDepot.get(name);
    if (configKey == 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");
    }
    String defaultValue = configKey.defaultValue();
    String category = configKey.category();
    String configScope = configKey.scope().toString();
    String scope = "";
    Map<String, Long> scopeMap = new LinkedHashMap<>();
    Long id = null;
    int paramCountCheck = 0;
    scopeMap.put(ConfigKey.Scope.Zone.toString(), zoneId);
    scopeMap.put(ConfigKey.Scope.Cluster.toString(), clusterId);
    scopeMap.put(ConfigKey.Scope.Domain.toString(), domainId);
    scopeMap.put(ConfigKey.Scope.Account.toString(), accountId);
    scopeMap.put(ConfigKey.Scope.StoragePool.toString(), storagepoolId);
    scopeMap.put(ConfigKey.Scope.ImageStore.toString(), imageStoreId);
    ParamCountPair paramCountPair = getParamCount(scopeMap);
    id = paramCountPair.getId();
    paramCountCheck = paramCountPair.getParamCount();
    scope = paramCountPair.getScope();
    if (paramCountCheck > 1) {
        throw new InvalidParameterValueException("cannot handle multiple IDs, provide only one ID corresponding to the scope");
    }
    if (scope != null && !scope.equals(ConfigKey.Scope.Global.toString()) && !configScope.contains(scope)) {
        throw new InvalidParameterValueException("Invalid scope id provided for the parameter " + name);
    }
    String newValue = null;
    switch(ConfigKey.Scope.valueOf(scope)) {
        case Zone:
            final DataCenterVO zone = _zoneDao.findById(id);
            if (zone == null) {
                throw new InvalidParameterValueException("unable to find zone by id " + id);
            }
            _dcDetailsDao.removeDetail(id, name);
            optionalValue = Optional.ofNullable(configKey.valueIn(id));
            newValue = optionalValue.isPresent() ? optionalValue.get().toString() : defaultValue;
            break;
        case Cluster:
            final ClusterVO cluster = _clusterDao.findById(id);
            if (cluster == null) {
                throw new InvalidParameterValueException("unable to find cluster by id " + id);
            }
            ClusterDetailsVO clusterDetailsVO = _clusterDetailsDao.findDetail(id, name);
            newValue = configKey.value().toString();
            if (name.equalsIgnoreCase("cpu.overprovisioning.factor") || name.equalsIgnoreCase("mem.overprovisioning.factor")) {
                _clusterDetailsDao.persist(id, name, newValue);
            } else if (clusterDetailsVO != null) {
                _clusterDetailsDao.remove(clusterDetailsVO.getId());
            }
            optionalValue = Optional.ofNullable(configKey.valueIn(id));
            newValue = optionalValue.isPresent() ? optionalValue.get().toString() : defaultValue;
            break;
        case StoragePool:
            final StoragePoolVO pool = _storagePoolDao.findById(id);
            if (pool == null) {
                throw new InvalidParameterValueException("unable to find storage pool by id " + id);
            }
            _storagePoolDetailsDao.removeDetail(id, name);
            optionalValue = Optional.ofNullable(configKey.valueIn(id));
            newValue = optionalValue.isPresent() ? optionalValue.get().toString() : defaultValue;
            break;
        case Domain:
            final DomainVO domain = _domainDao.findById(id);
            if (domain == null) {
                throw new InvalidParameterValueException("unable to find domain by id " + id);
            }
            DomainDetailVO domainDetailVO = _domainDetailsDao.findDetail(id, name);
            if (domainDetailVO != null) {
                _domainDetailsDao.remove(domainDetailVO.getId());
            }
            optionalValue = Optional.ofNullable(configKey.valueIn(id));
            newValue = optionalValue.isPresent() ? optionalValue.get().toString() : defaultValue;
            break;
        case Account:
            final AccountVO account = _accountDao.findById(id);
            if (account == null) {
                throw new InvalidParameterValueException("unable to find account by id " + id);
            }
            AccountDetailVO accountDetailVO = _accountDetailsDao.findDetail(id, name);
            if (accountDetailVO != null) {
                _accountDetailsDao.remove(accountDetailVO.getId());
            }
            optionalValue = Optional.ofNullable(configKey.valueIn(id));
            newValue = optionalValue.isPresent() ? optionalValue.get().toString() : defaultValue;
            break;
        case ImageStore:
            final ImageStoreVO imageStoreVO = _imageStoreDao.findById(id);
            if (imageStoreVO == null) {
                throw new InvalidParameterValueException("unable to find the image store by id " + id);
            }
            ImageStoreDetailVO imageStoreDetailVO = _imageStoreDetailsDao.findDetail(id, name);
            if (imageStoreDetailVO != null) {
                _imageStoreDetailsDao.remove(imageStoreDetailVO.getId());
            }
            optionalValue = Optional.ofNullable(configKey.valueIn(id));
            newValue = optionalValue.isPresent() ? optionalValue.get().toString() : defaultValue;
            break;
        default:
            if (!_configDao.update(name, category, defaultValue)) {
                s_logger.error("Failed to reset configuration option, name: " + name + ", defaultValue:" + defaultValue);
                throw new CloudRuntimeException("Failed to reset configuration value. Please contact Cloud Support.");
            }
            optionalValue = Optional.ofNullable(configKey.value());
            newValue = optionalValue.isPresent() ? optionalValue.get().toString() : defaultValue;
    }
    CallContext.current().setEventDetails(" Name: " + name + " New Value: " + (name.toLowerCase().contains("password") ? "*****" : defaultValue == null ? "" : defaultValue));
    return new Pair<Configuration, String>(_configDao.findByName(name), newValue);
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) ImageStoreDetailVO(org.apache.cloudstack.storage.datastore.db.ImageStoreDetailVO) ClusterVO(com.cloud.dc.ClusterVO) Optional(java.util.Optional) DomainDetailVO(com.cloud.domain.DomainDetailVO) AccountVO(com.cloud.user.AccountVO) LinkedHashMap(java.util.LinkedHashMap) DomainVO(com.cloud.domain.DomainVO) AccountDetailVO(com.cloud.user.AccountDetailVO) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) ImageStoreVO(org.apache.cloudstack.storage.datastore.db.ImageStoreVO) ClusterDetailsVO(com.cloud.dc.ClusterDetailsVO) Pair(com.cloud.utils.Pair) ActionEvent(com.cloud.event.ActionEvent)

Example 2 with DomainDetailVO

use of com.cloud.domain.DomainDetailVO in project cloudstack by apache.

the class DomainDetailsDaoImpl method findDetails.

@Override
public Map<String, String> findDetails(long domainId) {
    QueryBuilder<DomainDetailVO> sc = QueryBuilder.create(DomainDetailVO.class);
    sc.and(sc.entity().getDomainId(), Op.EQ, domainId);
    List<DomainDetailVO> results = sc.list();
    Map<String, String> details = new HashMap<String, String>(results.size());
    for (DomainDetailVO r : results) {
        details.put(r.getName(), r.getValue());
    }
    return details;
}
Also used : DomainDetailVO(com.cloud.domain.DomainDetailVO) HashMap(java.util.HashMap)

Example 3 with DomainDetailVO

use of com.cloud.domain.DomainDetailVO in project cloudstack by apache.

the class DomainDetailsDaoImpl method deleteDetails.

@Override
public void deleteDetails(long domainId) {
    SearchCriteria<DomainDetailVO> sc = domainSearch.create();
    sc.setParameters("domainId", domainId);
    List<DomainDetailVO> results = search(sc, null);
    for (DomainDetailVO result : results) {
        remove(result.getId());
    }
}
Also used : DomainDetailVO(com.cloud.domain.DomainDetailVO)

Example 4 with DomainDetailVO

use of com.cloud.domain.DomainDetailVO in project cloudstack by apache.

the class DomainDetailsDaoImpl method getConfigValue.

@Override
public String getConfigValue(long id, ConfigKey<?> key) {
    DomainDetailVO vo = null;
    String enableDomainSettingsForChildDomain = _configDao.getValue("enable.domain.settings.for.child.domain");
    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();
}
Also used : DomainVO(com.cloud.domain.DomainVO) DomainDetailVO(com.cloud.domain.DomainDetailVO)

Example 5 with DomainDetailVO

use of com.cloud.domain.DomainDetailVO in project cloudstack by apache.

the class DomainDetailsDaoImpl method persist.

@Override
public void persist(long domainId, Map<String, String> details) {
    TransactionLegacy txn = TransactionLegacy.currentTxn();
    txn.start();
    SearchCriteria<DomainDetailVO> sc = domainSearch.create();
    sc.setParameters("domainId", domainId);
    expunge(sc);
    for (Map.Entry<String, String> detail : details.entrySet()) {
        DomainDetailVO vo = new DomainDetailVO(domainId, detail.getKey(), detail.getValue());
        persist(vo);
    }
    txn.commit();
}
Also used : TransactionLegacy(com.cloud.utils.db.TransactionLegacy) DomainDetailVO(com.cloud.domain.DomainDetailVO) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

DomainDetailVO (com.cloud.domain.DomainDetailVO)7 DomainVO (com.cloud.domain.DomainVO)4 ClusterDetailsVO (com.cloud.dc.ClusterDetailsVO)2 ClusterVO (com.cloud.dc.ClusterVO)2 DataCenterVO (com.cloud.dc.DataCenterVO)2 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)2 AccountDetailVO (com.cloud.user.AccountDetailVO)2 AccountVO (com.cloud.user.AccountVO)2 TransactionLegacy (com.cloud.utils.db.TransactionLegacy)2 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)2 HashMap (java.util.HashMap)2 ImageStoreVO (org.apache.cloudstack.storage.datastore.db.ImageStoreVO)2 StoragePoolVO (org.apache.cloudstack.storage.datastore.db.StoragePoolVO)2 ActionEvent (com.cloud.event.ActionEvent)1 Pair (com.cloud.utils.Pair)1 DB (com.cloud.utils.db.DB)1 Date (java.sql.Date)1 PreparedStatement (java.sql.PreparedStatement)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1