Search in sources :

Example 61 with StoragePoolVO

use of org.apache.cloudstack.storage.datastore.db.StoragePoolVO in project cloudstack by apache.

the class SolidFireHostListener method getTargets.

private List<Map<String, String>> getTargets(long clusterId, long storagePoolId) {
    List<Map<String, String>> targets = new ArrayList<>();
    StoragePoolVO storagePool = storagePoolDao.findById(storagePoolId);
    // If you do not pass in null for the second parameter, you only get back applicable ROOT disks.
    List<VolumeVO> volumes = volumeDao.findByPoolId(storagePoolId, null);
    if (volumes != null) {
        for (VolumeVO volume : volumes) {
            Long instanceId = volume.getInstanceId();
            if (instanceId != null) {
                VMInstanceVO vmInstance = vmDao.findById(instanceId);
                Long hostIdForVm = vmInstance.getHostId() != null ? vmInstance.getHostId() : vmInstance.getLastHostId();
                if (hostIdForVm != null) {
                    HostVO hostForVm = hostDao.findById(hostIdForVm);
                    if (hostForVm.getClusterId().equals(clusterId)) {
                        Map<String, String> details = new HashMap<>();
                        details.put(ModifyTargetsCommand.IQN, volume.get_iScsiName());
                        details.put(ModifyTargetsCommand.STORAGE_HOST, storagePool.getHostAddress());
                        details.put(ModifyTargetsCommand.STORAGE_PORT, String.valueOf(storagePool.getPort()));
                        targets.add(details);
                    }
                }
            }
        }
    }
    return targets;
}
Also used : VolumeVO(com.cloud.storage.VolumeVO) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) VMInstanceVO(com.cloud.vm.VMInstanceVO) HashMap(java.util.HashMap) Map(java.util.Map) HostVO(com.cloud.host.HostVO) StoragePoolHostVO(com.cloud.storage.StoragePoolHostVO)

Example 62 with StoragePoolVO

use of org.apache.cloudstack.storage.datastore.db.StoragePoolVO in project cloudstack by apache.

the class SolidFireHostListener method handleVMware.

private void handleVMware(HostVO host, boolean add, ModifyTargetsCommand.TargetTypeToRemove targetTypeToRemove) {
    if (host != null && HypervisorType.VMware.equals(host.getHypervisorType())) {
        List<StoragePoolVO> storagePools = storagePoolDao.findPoolsByProvider(SolidFireUtil.PROVIDER_NAME);
        if (storagePools != null && storagePools.size() > 0) {
            List<Map<String, String>> targets = new ArrayList<>();
            for (StoragePoolVO storagePool : storagePools) {
                List<Map<String, String>> targetsForClusterAndStoragePool = getTargets(host.getClusterId(), storagePool.getId());
                targets.addAll(targetsForClusterAndStoragePool);
            }
            ModifyTargetsCommand cmd = new ModifyTargetsCommand();
            cmd.setTargets(targets);
            cmd.setAdd(add);
            cmd.setTargetTypeToRemove(targetTypeToRemove);
            cmd.setRemoveAsync(true);
            sendModifyTargetsCommand(cmd, host.getId());
        }
    }
}
Also used : ModifyTargetsCommand(com.cloud.agent.api.ModifyTargetsCommand) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) Map(java.util.Map)

Example 63 with StoragePoolVO

use of org.apache.cloudstack.storage.datastore.db.StoragePoolVO in project cloudstack by apache.

the class SolidFireSharedHostListener method hostConnect.

@Override
public boolean hostConnect(long hostId, long storagePoolId) {
    StoragePool storagePool = (StoragePool) dataStoreMgr.getDataStore(storagePoolId, DataStoreRole.Primary);
    ModifyStoragePoolCommand cmd = new ModifyStoragePoolCommand(true, storagePool);
    ModifyStoragePoolAnswer answer = sendModifyStoragePoolCommand(cmd, storagePool, hostId);
    StoragePoolHostVO storagePoolHost = storagePoolHostDao.findByPoolHost(storagePoolId, hostId);
    if (storagePoolHost != null) {
        storagePoolHost.setLocalPath(answer.getPoolInfo().getLocalPath().replaceAll("//", "/"));
    } else {
        storagePoolHost = new StoragePoolHostVO(storagePoolId, hostId, answer.getPoolInfo().getLocalPath().replaceAll("//", "/"));
        storagePoolHostDao.persist(storagePoolHost);
    }
    StoragePoolVO storagePoolVO = storagePoolDao.findById(storagePoolId);
    storagePoolVO.setCapacityBytes(answer.getPoolInfo().getCapacityBytes());
    storagePoolVO.setUsedBytes(answer.getPoolInfo().getCapacityBytes() - answer.getPoolInfo().getAvailableBytes());
    storagePoolDao.update(storagePoolId, storagePoolVO);
    return true;
}
Also used : StoragePool(com.cloud.storage.StoragePool) StoragePoolHostVO(com.cloud.storage.StoragePoolHostVO) ModifyStoragePoolAnswer(com.cloud.agent.api.ModifyStoragePoolAnswer) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) ModifyStoragePoolCommand(com.cloud.agent.api.ModifyStoragePoolCommand)

Example 64 with StoragePoolVO

use of org.apache.cloudstack.storage.datastore.db.StoragePoolVO 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 65 with StoragePoolVO

use of org.apache.cloudstack.storage.datastore.db.StoragePoolVO in project cloudstack by apache.

the class VolumeTest method createPrimaryDataStore.

public DataStore createPrimaryDataStore() {
    try {
        List<StoragePoolVO> pools = primaryDataStoreDao.findPoolByName(this.primaryName);
        if (pools.size() > 0) {
            return this.dataStoreMgr.getPrimaryDataStore(pools.get(0).getId());
        }
        /*
             * DataStoreProvider provider =
             * dataStoreProviderMgr.getDataStoreProvider
             * ("cloudstack primary data store provider"); Map<String, Object>
             * params = new HashMap<String, Object>(); URI uri = new
             * URI(this.getPrimaryStorageUrl()); params.put("url",
             * this.getPrimaryStorageUrl()); params.put("server",
             * uri.getHost()); params.put("path", uri.getPath());
             * params.put("protocol",
             * Storage.StoragePoolType.NetworkFilesystem); params.put("zoneId",
             * dcId); params.put("clusterId", clusterId); params.put("name",
             * this.primaryName); params.put("port", 1); params.put("podId",
             * this.podId); params.put("roles",
             * DataStoreRole.Primary.toString()); params.put("uuid", uuid);
             * params.put("providerName", String.valueOf(provider.getName()));
             *
             * DataStoreLifeCycle lifeCycle = provider.getDataStoreLifeCycle();
             * DataStore store = lifeCycle.initialize(params); ClusterScope
             * scope = new ClusterScope(clusterId, podId, dcId);
             * lifeCycle.attachCluster(store, scope);
             */
        StoragePoolVO pool = new StoragePoolVO();
        pool.setClusterId(clusterId);
        pool.setDataCenterId(dcId);
        URI uri = new URI(this.getPrimaryStorageUrl());
        pool.setHostAddress(uri.getHost());
        pool.setPath(uri.getPath());
        pool.setPort(0);
        pool.setName(this.primaryName);
        pool.setUuid(this.getPrimaryStorageUuid());
        pool.setStatus(StoragePoolStatus.Up);
        pool.setPoolType(StoragePoolType.NetworkFilesystem);
        pool.setPodId(podId);
        pool.setScope(ScopeType.CLUSTER);
        pool.setStorageProviderName(DataStoreProvider.DEFAULT_PRIMARY);
        pool = this.primaryStoreDao.persist(pool);
        DataStore store = this.dataStoreMgr.getPrimaryDataStore(pool.getId());
        return store;
    } catch (Exception e) {
        return null;
    }
}
Also used : DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) URI(java.net.URI) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

StoragePoolVO (org.apache.cloudstack.storage.datastore.db.StoragePoolVO)276 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)106 VMTemplateStoragePoolVO (com.cloud.storage.VMTemplateStoragePoolVO)75 ArrayList (java.util.ArrayList)54 VolumeVO (com.cloud.storage.VolumeVO)53 HostVO (com.cloud.host.HostVO)46 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)45 DataStore (org.apache.cloudstack.engine.subsystem.api.storage.DataStore)45 HashMap (java.util.HashMap)44 Answer (com.cloud.agent.api.Answer)38 VolumeInfo (org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo)35 StoragePool (com.cloud.storage.StoragePool)33 Test (org.junit.Test)33 VMInstanceVO (com.cloud.vm.VMInstanceVO)25 Map (java.util.Map)25 Account (com.cloud.user.Account)24 HypervisorType (com.cloud.hypervisor.Hypervisor.HypervisorType)20 ExecutionException (java.util.concurrent.ExecutionException)20 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)19 ClusterVO (com.cloud.dc.ClusterVO)18