Search in sources :

Example 16 with ConfigurationVO

use of org.apache.cloudstack.framework.config.impl.ConfigurationVO in project cloudstack by apache.

the class ConfigurationServerImpl method updateSecondaryStorageVMSharedKey.

/**
 * preshared key to be used by management server to communicate with SSVM during volume/template upload
 */
private void updateSecondaryStorageVMSharedKey() {
    try {
        ConfigurationVO configInDB = _configDao.findByName(Config.SSVMPSK.key());
        if (configInDB == null) {
            ConfigurationVO configVO = new ConfigurationVO(Config.SSVMPSK.getCategory(), "DEFAULT", Config.SSVMPSK.getComponent(), Config.SSVMPSK.key(), getPrivateKey(), Config.SSVMPSK.getDescription());
            s_logger.info("generating a new SSVM PSK. This goes to SSVM on Start");
            _configDao.persist(configVO);
        } else if (StringUtils.isEmpty(configInDB.getValue())) {
            s_logger.info("updating the SSVM PSK with new value. This goes to SSVM on Start");
            _configDao.update(Config.SSVMPSK.key(), Config.SSVMPSK.getCategory(), getPrivateKey());
        }
    } catch (NoSuchAlgorithmException ex) {
        s_logger.error("error generating ssvm psk", ex);
    }
}
Also used : ConfigurationVO(org.apache.cloudstack.framework.config.impl.ConfigurationVO) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException)

Example 17 with ConfigurationVO

use of org.apache.cloudstack.framework.config.impl.ConfigurationVO in project cloudstack by apache.

the class ManagementServerImpl method searchForConfigurations.

@Override
public Pair<List<? extends Configuration>, Integer> searchForConfigurations(final ListCfgsByCmd cmd) {
    final Filter searchFilter = new Filter(ConfigurationVO.class, "name", true, cmd.getStartIndex(), cmd.getPageSizeVal());
    final SearchCriteria<ConfigurationVO> sc = _configDao.createSearchCriteria();
    final Object name = cmd.getConfigName();
    final Object category = cmd.getCategory();
    final Object keyword = cmd.getKeyword();
    final Long zoneId = cmd.getZoneId();
    final Long clusterId = cmd.getClusterId();
    final Long storagepoolId = cmd.getStoragepoolId();
    final Long imageStoreId = cmd.getImageStoreId();
    Long accountId = cmd.getAccountId();
    Long domainId = cmd.getDomainId();
    String scope = null;
    Long id = null;
    int paramCountCheck = 0;
    final Account caller = CallContext.current().getCallingAccount();
    if (_accountMgr.isDomainAdmin(caller.getId())) {
        if (accountId == null && domainId == null) {
            domainId = caller.getDomainId();
        }
    } else if (_accountMgr.isNormalUser(caller.getId())) {
        if (accountId == null) {
            accountId = caller.getAccountId();
        }
    }
    if (zoneId != null) {
        scope = ConfigKey.Scope.Zone.toString();
        id = zoneId;
        paramCountCheck++;
    }
    if (clusterId != null) {
        scope = ConfigKey.Scope.Cluster.toString();
        id = clusterId;
        paramCountCheck++;
    }
    if (accountId != null) {
        Account account = _accountMgr.getAccount(accountId);
        _accountMgr.checkAccess(caller, null, false, account);
        scope = ConfigKey.Scope.Account.toString();
        id = accountId;
        paramCountCheck++;
    }
    if (domainId != null) {
        _accountMgr.checkAccess(caller, _domainDao.findById(domainId));
        scope = ConfigKey.Scope.Domain.toString();
        id = domainId;
        paramCountCheck++;
    }
    if (storagepoolId != null) {
        scope = ConfigKey.Scope.StoragePool.toString();
        id = storagepoolId;
        paramCountCheck++;
    }
    if (imageStoreId != null) {
        scope = ConfigKey.Scope.ImageStore.toString();
        id = imageStoreId;
        paramCountCheck++;
    }
    if (paramCountCheck > 1) {
        throw new InvalidParameterValueException("cannot handle multiple IDs, provide only one ID corresponding to the scope");
    }
    if (keyword != null) {
        final SearchCriteria<ConfigurationVO> ssc = _configDao.createSearchCriteria();
        ssc.addOr("name", SearchCriteria.Op.LIKE, "%" + keyword + "%");
        ssc.addOr("instance", SearchCriteria.Op.LIKE, "%" + keyword + "%");
        ssc.addOr("component", SearchCriteria.Op.LIKE, "%" + keyword + "%");
        ssc.addOr("description", SearchCriteria.Op.LIKE, "%" + keyword + "%");
        ssc.addOr("category", SearchCriteria.Op.LIKE, "%" + keyword + "%");
        ssc.addOr("value", SearchCriteria.Op.LIKE, "%" + keyword + "%");
        sc.addAnd("name", SearchCriteria.Op.SC, ssc);
    }
    if (name != null) {
        sc.addAnd("name", SearchCriteria.Op.LIKE, "%" + name + "%");
    }
    if (category != null) {
        sc.addAnd("category", SearchCriteria.Op.EQ, category);
    }
    // hidden configurations are not displayed using the search API
    sc.addAnd("category", SearchCriteria.Op.NEQ, "Hidden");
    if (scope != null && !scope.isEmpty()) {
        // getting the list of parameters at requested scope
        if (ConfigurationManagerImpl.ENABLE_ACCOUNT_SETTINGS_FOR_DOMAIN.value() && scope.equals(ConfigKey.Scope.Domain.toString())) {
            sc.addAnd("scope", SearchCriteria.Op.IN, ConfigKey.Scope.Domain.toString(), ConfigKey.Scope.Account.toString());
        } else {
            sc.addAnd("scope", SearchCriteria.Op.EQ, scope);
        }
    }
    final Pair<List<ConfigurationVO>, Integer> result = _configDao.searchAndCount(sc, searchFilter);
    if (scope != null && !scope.isEmpty()) {
        // Populate values corresponding the resource id
        final List<ConfigurationVO> configVOList = new ArrayList<ConfigurationVO>();
        for (final ConfigurationVO param : result.first()) {
            final ConfigurationVO configVo = _configDao.findByName(param.getName());
            if (configVo != null) {
                final ConfigKey<?> key = _configDepot.get(param.getName());
                if (key != null) {
                    if (scope.equals(ConfigKey.Scope.Domain.toString())) {
                        Object value = key.valueInDomain(id);
                        configVo.setValue(value == null ? null : value.toString());
                    } else {
                        Object value = key.valueIn(id);
                        configVo.setValue(value == null ? null : value.toString());
                    }
                    configVOList.add(configVo);
                } else {
                    s_logger.warn("ConfigDepot could not find parameter " + param.getName() + " for scope " + scope);
                }
            } else {
                s_logger.warn("Configuration item  " + param.getName() + " not found in " + scope);
            }
        }
        return new Pair<List<? extends Configuration>, Integer>(configVOList, configVOList.size());
    }
    return new Pair<List<? extends Configuration>, Integer>(result.first(), result.second());
}
Also used : Account(com.cloud.user.Account) ArrayList(java.util.ArrayList) ConfigurationVO(org.apache.cloudstack.framework.config.impl.ConfigurationVO) Filter(com.cloud.utils.db.Filter) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) ArrayList(java.util.ArrayList) ExcludeList(com.cloud.deploy.DeploymentPlanner.ExcludeList) List(java.util.List) Pair(com.cloud.utils.Pair) SSHKeyPair(com.cloud.user.SSHKeyPair)

Example 18 with ConfigurationVO

use of org.apache.cloudstack.framework.config.impl.ConfigurationVO in project cloudstack by apache.

the class LDAPConfigCmd method updateLDAP.

private boolean updateLDAP() {
    _ldapManager.addConfiguration(hostname, port, null);
    /**
     * There is no query filter now. It is derived from ldap.user.object and ldap.search.group.principle
     */
    // ConfigurationVO cvo = _configDao.findByName(LDAPParams.queryfilter.toString());
    // _configDao.update(cvo.getName(),cvo.getCategory(),getQueryFilter());
    ConfigurationVO cvo = _configDao.findByName("ldap.basedn");
    _configDao.update(cvo.getName(), cvo.getCategory(), getSearchBase());
    /**
     * There is no ssl now. it is derived from the presence of trust store and password
     */
    // cvo = _configDao.findByName(LDAPParams.usessl.toString());
    // _configDao.update(cvo.getName(),cvo.getCategory(),getUseSSL().toString());
    cvo = _configDao.findByName("ldap.bind.principal");
    _configDao.update(cvo.getName(), cvo.getCategory(), getBindDN());
    cvo = _configDao.findByName("ldap.bind.password");
    _configDao.update(cvo.getName(), cvo.getCategory(), getBindPassword());
    cvo = _configDao.findByName("ldap.truststore");
    _configDao.update(cvo.getName(), cvo.getCategory(), getTrustStore());
    cvo = _configDao.findByName("ldap.truststore.password");
    _configDao.update(cvo.getName(), cvo.getCategory(), getTrustStorePassword());
    return true;
}
Also used : LdapConfigurationVO(org.apache.cloudstack.ldap.LdapConfigurationVO) ConfigurationVO(org.apache.cloudstack.framework.config.impl.ConfigurationVO)

Example 19 with ConfigurationVO

use of org.apache.cloudstack.framework.config.impl.ConfigurationVO in project cloudstack by apache.

the class ConfigurationDaoImpl method getConfiguration.

@Override
public Map<String, String> getConfiguration(String instance, Map<String, ? extends Object> params) {
    if (_configs == null) {
        _configs = new HashMap<String, String>();
        SearchCriteria<ConfigurationVO> sc = InstanceSearch.create();
        sc.setParameters("instance", "DEFAULT");
        List<ConfigurationVO> configurations = listIncludingRemovedBy(sc);
        for (ConfigurationVO config : configurations) {
            if (config.getValue() != null)
                _configs.put(config.getName(), config.getValue());
        }
        if (!"DEFAULT".equals(instance)) {
            // Default instance params are already added, need not add again
            sc = InstanceSearch.create();
            sc.setParameters("instance", instance);
            configurations = listIncludingRemovedBy(sc);
            for (ConfigurationVO config : configurations) {
                _configs.put(config.getName(), config.getValue());
            }
        }
    }
    mergeConfigs(_configs, params);
    return _configs;
}
Also used : ConfigurationVO(org.apache.cloudstack.framework.config.impl.ConfigurationVO)

Aggregations

ConfigurationVO (org.apache.cloudstack.framework.config.impl.ConfigurationVO)19 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)4 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)4 ArrayList (java.util.ArrayList)3 ConfigurationException (javax.naming.ConfigurationException)3 Before (org.junit.Before)3 IPRangeConfig (com.cloud.test.IPRangeConfig)2 Account (com.cloud.user.Account)2 DB (com.cloud.utils.db.DB)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 HashMap (java.util.HashMap)2 NuageTest (com.cloud.NuageTest)1 SyncNuageVspCmsIdAnswer (com.cloud.agent.api.sync.SyncNuageVspCmsIdAnswer)1 DeleteNuageVspDeviceCmd (com.cloud.api.commands.DeleteNuageVspDeviceCmd)1 Config (com.cloud.configuration.Config)1 VlanVO (com.cloud.dc.VlanVO)1 ExcludeList (com.cloud.deploy.DeploymentPlanner.ExcludeList)1 ActionEvent (com.cloud.event.ActionEvent)1 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)1 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)1