Search in sources :

Example 11 with ConfigurationVO

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

the class ConfigurationServerImpl method persistDefaultValues.

@Override
public void persistDefaultValues() throws InternalErrorException {
    // Create system user and admin user
    saveUser();
    // Get init
    String init = _configDao.getValue("init");
    if (init == null || init.equals("false")) {
        s_logger.debug("ConfigurationServer is saving default values to the database.");
        // Save default Configuration Table values
        List<String> categories = Config.getCategories();
        for (String category : categories) {
            // If this is not a premium environment, don't insert premium configuration values
            if (!_configDao.isPremium() && category.equals("Premium")) {
                continue;
            }
            List<Config> configs = Config.getConfigs(category);
            for (Config c : configs) {
                String name = c.key();
                // if the config value already present in the db, don't insert it again
                if (_configDao.findByName(name) != null) {
                    continue;
                }
                String instance = "DEFAULT";
                String component = c.getComponent();
                String value = c.getDefaultValue();
                String description = c.getDescription();
                ConfigurationVO configVO = new ConfigurationVO(category, instance, component, name, value, description);
                configVO.setDefaultValue(value);
                _configDao.persist(configVO);
            }
        }
        _configDao.update(Config.UseSecondaryStorageVm.key(), Config.UseSecondaryStorageVm.getCategory(), "true");
        s_logger.debug("ConfigurationServer made secondary storage vm required.");
        _configDao.update(Config.SecStorageEncryptCopy.key(), Config.SecStorageEncryptCopy.getCategory(), "false");
        s_logger.debug("ConfigurationServer made secondary storage copy encrypt set to false.");
        _configDao.update("secstorage.secure.copy.cert", "realhostip");
        s_logger.debug("ConfigurationServer made secondary storage copy use realhostip.");
        _configDao.update("user.password.encoders.exclude", "MD5,LDAP,PLAINTEXT");
        s_logger.debug("Configuration server excluded insecure encoders");
        _configDao.update("user.authenticators.exclude", "PLAINTEXT");
        s_logger.debug("Configuration server excluded plaintext authenticator");
        // Save default service offerings
        createServiceOffering(User.UID_SYSTEM, "Small Instance", 1, 512, 500, "Small Instance", ProvisioningType.THIN, false, false, null);
        createServiceOffering(User.UID_SYSTEM, "Medium Instance", 1, 1024, 1000, "Medium Instance", ProvisioningType.THIN, false, false, null);
        // Save default disk offerings
        createDefaultDiskOffering("Small", "Small Disk, 5 GB", ProvisioningType.THIN, 5, null, false, false);
        createDefaultDiskOffering("Medium", "Medium Disk, 20 GB", ProvisioningType.THIN, 20, null, false, false);
        createDefaultDiskOffering("Large", "Large Disk, 100 GB", ProvisioningType.THIN, 100, null, false, false);
        createDefaultDiskOffering("Large", "Large Disk, 100 GB", ProvisioningType.THIN, 100, null, false, false);
        createDefaultDiskOffering("Custom", "Custom Disk", ProvisioningType.THIN, 0, null, true, false);
        // Save the mount parent to the configuration table
        String mountParent = getMountParent();
        if (mountParent != null) {
            _configDao.update(Config.MountParent.key(), Config.MountParent.getCategory(), mountParent);
            s_logger.debug("ConfigurationServer saved \"" + mountParent + "\" as mount.parent.");
        } else {
            s_logger.debug("ConfigurationServer could not detect mount.parent.");
        }
        String hostIpAdr = NetUtils.getDefaultHostIp();
        boolean needUpdateHostIp = true;
        if (hostIpAdr != null) {
            Boolean devel = Boolean.valueOf(_configDao.getValue("developer"));
            if (devel) {
                String value = _configDao.getValue(ApiServiceConfiguration.ManagementServerAddresses.key());
                if (value != null && !value.equals("localhost")) {
                    needUpdateHostIp = false;
                }
            }
            if (needUpdateHostIp) {
                _configDepot.createOrUpdateConfigObject(ApiServiceConfiguration.class.getSimpleName(), ApiServiceConfiguration.ManagementServerAddresses, hostIpAdr);
                s_logger.debug("ConfigurationServer saved \"" + hostIpAdr + "\" as host.");
            }
        }
        // generate a single sign-on key
        updateSSOKey();
        // Create default network offerings
        createDefaultNetworkOfferings();
        // Create default networks
        createDefaultNetworks();
        // Create userIpAddress ranges
        // Update existing vlans with networkId
        List<VlanVO> vlans = _vlanDao.listAll();
        if (vlans != null && !vlans.isEmpty()) {
            for (final VlanVO vlan : vlans) {
                if (vlan.getNetworkId().longValue() == 0) {
                    updateVlanWithNetworkId(vlan);
                }
                // Create vlan user_ip_address range
                String ipPange = vlan.getIpRange();
                String[] range = ipPange.split("-");
                final String startIp = range[0];
                final String endIp = range[1];
                Transaction.execute(new TransactionCallbackNoReturn() {

                    @Override
                    public void doInTransactionWithoutResult(TransactionStatus status) {
                        IPRangeConfig config = new IPRangeConfig();
                        long startIPLong = NetUtils.ip2Long(startIp);
                        long endIPLong = NetUtils.ip2Long(endIp);
                        config.savePublicIPRange(TransactionLegacy.currentTxn(), startIPLong, endIPLong, vlan.getDataCenterId(), vlan.getId(), vlan.getNetworkId(), vlan.getPhysicalNetworkId(), false);
                    }
                });
            }
        }
    }
    // Update resource count if needed
    updateResourceCount();
    // store the public and private keys in the database
    updateKeyPairs();
    // generate a PSK to communicate with SSVM
    updateSecondaryStorageVMSharedKey();
    // generate a random password for system vm
    updateSystemvmPassword();
    // generate a random password used to authenticate zone-to-zone copy
    generateSecStorageVmCopyPassword();
    // Update the cloud identifier
    updateCloudIdentifier();
    _configDepotAdmin.populateConfigurations();
    // setup XenServer default PV driver version
    initiateXenServerPVDriverVersion();
    // We should not update seed data UUID column here since this will be invoked in upgrade case as well.
    // updateUuids();
    // Set init to true
    _configDao.update("init", "Hidden", "true");
    // invalidate cache in DAO as we have changed DB status
    _configDao.invalidateCache();
}
Also used : Config(com.cloud.configuration.Config) IPRangeConfig(com.cloud.test.IPRangeConfig) IPRangeConfig(com.cloud.test.IPRangeConfig) TransactionStatus(com.cloud.utils.db.TransactionStatus) TransactionCallbackNoReturn(com.cloud.utils.db.TransactionCallbackNoReturn) ApiServiceConfiguration(org.apache.cloudstack.config.ApiServiceConfiguration) ConfigurationVO(org.apache.cloudstack.framework.config.impl.ConfigurationVO) VlanVO(com.cloud.dc.VlanVO)

Example 12 with ConfigurationVO

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

the class ConfigurationServerImpl method getConfigListByScope.

@Override
public List<ConfigurationVO> getConfigListByScope(String scope, Long resourceId) {
    // Getting the list of parameters defined at the scope
    Set<ConfigKey<?>> configList = _configDepot.getConfigListByScope(scope);
    List<ConfigurationVO> configVOList = new ArrayList<ConfigurationVO>();
    for (ConfigKey<?> param : configList) {
        ConfigurationVO configVo = _configDao.findByName(param.toString());
        configVo.setValue(_configDepot.get(param.toString()).valueIn(resourceId).toString());
        configVOList.add(configVo);
    }
    return configVOList;
}
Also used : ConfigKey(org.apache.cloudstack.framework.config.ConfigKey) ConfigurationVO(org.apache.cloudstack.framework.config.impl.ConfigurationVO) ArrayList(java.util.ArrayList)

Example 13 with ConfigurationVO

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

the class NuageVspManagerTest method testDeleteNuageVspDevice.

@Test
public void testDeleteNuageVspDevice() throws ConfigurationException {
    final PhysicalNetworkVO physicalNetwork = mock(PhysicalNetworkVO.class);
    when(physicalNetwork.getDataCenterId()).thenReturn(NETWORK_ID);
    when(physicalNetwork.getId()).thenReturn(NETWORK_ID);
    when(_physicalNetworkDao.findById(NETWORK_ID)).thenReturn(physicalNetwork);
    final NuageVspDeviceVO nuageVspDevice = mock(NuageVspDeviceVO.class);
    when(nuageVspDevice.getPhysicalNetworkId()).thenReturn(NETWORK_ID);
    when(nuageVspDevice.getHostId()).thenReturn(NETWORK_ID);
    when(_nuageVspDao.findById(NETWORK_ID)).thenReturn(nuageVspDevice);
    when(_networkDao.listByPhysicalNetwork(NETWORK_ID)).thenReturn(new ArrayList<NetworkVO>());
    final HostVO host = mock(HostVO.class);
    when(host.getId()).thenReturn(NETWORK_ID);
    when(_hostDao.findById(NETWORK_ID)).thenReturn(host);
    final DeleteNuageVspDeviceCmd cmd = mock(DeleteNuageVspDeviceCmd.class);
    when(cmd.getNuageVspDeviceId()).thenReturn(NETWORK_ID);
    ConfigurationVO cmsIdConfig = mock(ConfigurationVO.class);
    when(cmsIdConfig.getValue()).thenReturn("1:1");
    when(_configurationDao.findByName("nuagevsp.cms.id")).thenReturn(cmsIdConfig);
    final SyncNuageVspCmsIdAnswer answer = mock(SyncNuageVspCmsIdAnswer.class);
    when(answer.getResult()).thenReturn(true);
    when(_agentManager.easySend(eq(NETWORK_ID), (Command) any())).thenReturn(answer);
    _nuageVspManager.deleteNuageVspDevice(cmd);
}
Also used : NuageVspDeviceVO(com.cloud.network.NuageVspDeviceVO) NetworkVO(com.cloud.network.dao.NetworkVO) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) DeleteNuageVspDeviceCmd(com.cloud.api.commands.DeleteNuageVspDeviceCmd) ConfigurationVO(org.apache.cloudstack.framework.config.impl.ConfigurationVO) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) SyncNuageVspCmsIdAnswer(com.cloud.agent.api.sync.SyncNuageVspCmsIdAnswer) HostVO(com.cloud.host.HostVO) NuageTest(com.cloud.NuageTest) Test(org.junit.Test)

Example 14 with ConfigurationVO

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

the class ConfigurationServerImpl method updateSSLKeystore.

protected void updateSSLKeystore() {
    if (s_logger.isInfoEnabled()) {
        s_logger.info("Processing updateSSLKeyStore");
    }
    String dbString = _configDao.getValue("ssl.keystore");
    File confFile = PropertiesUtil.findConfigFile("db.properties");
    String confPath = null;
    String keystorePath = null;
    File keystoreFile = null;
    if (null != confFile) {
        confPath = confFile.getParent();
        keystorePath = confPath + Link.keystoreFile;
        keystoreFile = new File(keystorePath);
    }
    boolean dbExisted = (dbString != null && !dbString.isEmpty());
    s_logger.info("SSL keystore located at " + keystorePath);
    try {
        if (!dbExisted && null != confFile) {
            if (!keystoreFile.exists()) {
                generateDefaultKeystore(keystorePath);
                s_logger.info("Generated SSL keystore.");
            }
            String base64Keystore = getBase64Keystore(keystorePath);
            ConfigurationVO configVO = new ConfigurationVO("Hidden", "DEFAULT", "management-server", "ssl.keystore", base64Keystore, "SSL Keystore for the management servers");
            _configDao.persist(configVO);
            s_logger.info("Stored SSL keystore to database.");
        } else {
            // !keystoreFile.exists() and dbExisted
            // Export keystore to local file
            byte[] storeBytes = Base64.decodeBase64(dbString);
            String tmpKeystorePath = "/tmp/tmpkey";
            try (FileOutputStream fo = new FileOutputStream(tmpKeystorePath)) {
                fo.write(storeBytes);
                Script script = new Script(true, "cp", 5000, null);
                script.add("-f");
                script.add(tmpKeystorePath);
                //There is a chance, although small, that the keystorePath is null. In that case, do not add it to the script.
                if (null != keystorePath) {
                    script.add(keystorePath);
                }
                String result = script.execute();
                if (result != null) {
                    throw new IOException();
                }
            } catch (Exception e) {
                throw new IOException("Fail to create keystore file!", e);
            }
            s_logger.info("Stored database keystore to local.");
        }
    } catch (Exception ex) {
        s_logger.warn("Would use fail-safe keystore to continue.", ex);
    }
}
Also used : Script(com.cloud.utils.script.Script) ConfigurationVO(org.apache.cloudstack.framework.config.impl.ConfigurationVO) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) File(java.io.File) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) SQLException(java.sql.SQLException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) EOFException(java.io.EOFException) FileNotFoundException(java.io.FileNotFoundException) InternalErrorException(com.cloud.exception.InternalErrorException) ConfigurationException(javax.naming.ConfigurationException)

Example 15 with ConfigurationVO

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

the class ImageStoreDetailsUtilTest method setup.

@Before
public void setup() throws Exception {
    Map<String, String> imgStoreDetails = new HashMap<String, String>();
    String nfsVersionKey = CapacityManager.ImageStoreNFSVersion.key();
    imgStoreDetails.put(nfsVersionKey, String.valueOf(NFS_VERSION));
    when(imgStoreDetailsDao.getDetails(STORE_ID)).thenReturn(imgStoreDetails);
    ImageStoreVO imgStoreVO = mock(ImageStoreVO.class);
    when(imgStoreVO.getId()).thenReturn(Long.valueOf(STORE_ID));
    when(imgStoreDao.findByUuid(STORE_UUID)).thenReturn(imgStoreVO);
    ConfigurationVO confVO = mock(ConfigurationVO.class);
    String defaultValue = (NFS_VERSION_DEFAULT == null ? null : String.valueOf(NFS_VERSION_DEFAULT));
    when(confVO.getValue()).thenReturn(defaultValue);
    when(configurationDao.findByName(nfsVersionKey)).thenReturn(confVO);
    imageStoreDetailsUtil.imageStoreDao = imgStoreDao;
    imageStoreDetailsUtil.imageStoreDetailsDao = imgStoreDetailsDao;
    imageStoreDetailsUtil.configurationDao = configurationDao;
}
Also used : ConfigurationVO(org.apache.cloudstack.framework.config.impl.ConfigurationVO) HashMap(java.util.HashMap) ImageStoreVO(org.apache.cloudstack.storage.datastore.db.ImageStoreVO) Before(org.junit.Before)

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