Search in sources :

Example 41 with StoragePoolVO

use of com.cloud.storage.datastore.db.StoragePoolVO in project cosmic by MissionCriticalCloud.

the class StorageManagerImpl method ListByDataCenterHypervisor.

@Override
public List<StoragePoolVO> ListByDataCenterHypervisor(final long datacenterId, final HypervisorType type) {
    final List<StoragePoolVO> pools = _storagePoolDao.listByDataCenterId(datacenterId);
    final List<StoragePoolVO> retPools = new ArrayList<>();
    for (final StoragePoolVO pool : pools) {
        if (pool.getStatus() != StoragePoolStatus.Up) {
            continue;
        }
        if (pool.getScope() == ScopeType.ZONE) {
            if (pool.getHypervisor() != null && pool.getHypervisor() == type) {
                retPools.add(pool);
            }
        } else {
            final ClusterVO cluster = _clusterDao.findById(pool.getClusterId());
            if (type == cluster.getHypervisorType()) {
                retPools.add(pool);
            }
        }
    }
    Collections.shuffle(retPools);
    return retPools;
}
Also used : ClusterVO(com.cloud.dc.ClusterVO) StoragePoolVO(com.cloud.storage.datastore.db.StoragePoolVO) ArrayList(java.util.ArrayList)

Example 42 with StoragePoolVO

use of com.cloud.storage.datastore.db.StoragePoolVO in project cosmic by MissionCriticalCloud.

the class StorageManagerImpl method getStoragePoolUsedStats.

@Override
public CapacityVO getStoragePoolUsedStats(final Long poolId, final Long clusterId, final Long podId, final Long zoneId) {
    final SearchCriteria<StoragePoolVO> sc = _storagePoolDao.createSearchCriteria();
    List<StoragePoolVO> pools = new ArrayList<>();
    if (zoneId != null) {
        sc.addAnd("dataCenterId", SearchCriteria.Op.EQ, zoneId);
    }
    if (podId != null) {
        sc.addAnd("podId", SearchCriteria.Op.EQ, podId);
    }
    if (clusterId != null) {
        sc.addAnd("clusterId", SearchCriteria.Op.EQ, clusterId);
    }
    if (poolId != null) {
        sc.addAnd("hostOrPoolId", SearchCriteria.Op.EQ, poolId);
    }
    if (poolId != null) {
        pools.add(_storagePoolDao.findById(poolId));
    } else {
        pools = _storagePoolDao.search(sc, null);
    }
    final CapacityVO capacity = new CapacityVO(poolId, zoneId, podId, clusterId, 0, 0, Capacity.CAPACITY_TYPE_STORAGE);
    for (final StoragePoolVO PrimaryDataStoreVO : pools) {
        final StorageStats stats = ApiDBUtils.getStoragePoolStatistics(PrimaryDataStoreVO.getId());
        if (stats == null) {
            continue;
        }
        capacity.setUsedCapacity(stats.getByteUsed() + capacity.getUsedCapacity());
        capacity.setTotalCapacity(stats.getCapacityBytes() + capacity.getTotalCapacity());
    }
    return capacity;
}
Also used : CapacityVO(com.cloud.capacity.CapacityVO) StoragePoolVO(com.cloud.storage.datastore.db.StoragePoolVO) ArrayList(java.util.ArrayList)

Example 43 with StoragePoolVO

use of com.cloud.storage.datastore.db.StoragePoolVO in project cosmic by MissionCriticalCloud.

the class StorageManagerImpl method createCapacityEntry.

@Override
public void createCapacityEntry(final long poolId) {
    final StoragePoolVO storage = _storagePoolDao.findById(poolId);
    createCapacityEntry(storage, Capacity.CAPACITY_TYPE_STORAGE_ALLOCATED, 0);
}
Also used : StoragePoolVO(com.cloud.storage.datastore.db.StoragePoolVO)

Example 44 with StoragePoolVO

use of com.cloud.storage.datastore.db.StoragePoolVO in project cosmic by MissionCriticalCloud.

the class StorageManagerImpl method storagePoolHasEnoughIops.

@Override
public boolean storagePoolHasEnoughIops(final List<Volume> requestedVolumes, final StoragePool pool) {
    if (requestedVolumes == null || requestedVolumes.isEmpty() || pool == null) {
        return false;
    }
    // This check returns true for storage that does not specify IOPS.
    if (pool.getCapacityIops() == null) {
        s_logger.info("Storage pool " + pool.getName() + " (" + pool.getId() + ") does not supply IOPS capacity, assuming enough capacity");
        return true;
    }
    final StoragePoolVO storagePoolVo = _storagePoolDao.findById(pool.getId());
    final long currentIops = _capacityMgr.getUsedIops(storagePoolVo);
    long requestedIops = 0;
    for (final Volume requestedVolume : requestedVolumes) {
        final Long minIops = requestedVolume.getMinIops();
        if (minIops != null && minIops > 0) {
            requestedIops += minIops;
        }
    }
    final long futureIops = currentIops + requestedIops;
    return futureIops <= pool.getCapacityIops();
}
Also used : StoragePoolVO(com.cloud.storage.datastore.db.StoragePoolVO)

Example 45 with StoragePoolVO

use of com.cloud.storage.datastore.db.StoragePoolVO in project cosmic by MissionCriticalCloud.

the class ConfigurationManagerImpl method updateConfiguration.

@Override
@DB
public String updateConfiguration(final long userId, final String name, final String category, final String value, final String scope, final Long resourceId) {
    final String validationMsg = validateConfigurationValue(name, value, scope);
    if (validationMsg != null) {
        s_logger.error("Invalid configuration option, name: " + name + ", value:" + value);
        throw new InvalidParameterValueException(validationMsg);
    }
    // global parameter updation
    if (scope != null && !scope.isEmpty() && !ConfigKey.Scope.Global.toString().equalsIgnoreCase(scope)) {
        switch(ConfigKey.Scope.valueOf(scope)) {
            case Zone:
                final DataCenterVO zone = _zoneDao.findById(resourceId);
                if (zone == null) {
                    throw new InvalidParameterValueException("unable to find zone by id " + resourceId);
                }
                _dcDetailsDao.addDetail(resourceId, name, value, true);
                break;
            case Cluster:
                final ClusterVO cluster = _clusterDao.findById(resourceId);
                if (cluster == null) {
                    throw new InvalidParameterValueException("unable to find cluster by id " + resourceId);
                }
                ClusterDetailsVO clusterDetailsVO = _clusterDetailsDao.findDetail(resourceId, name);
                if (clusterDetailsVO == null) {
                    clusterDetailsVO = new ClusterDetailsVO(resourceId, name, value);
                    _clusterDetailsDao.persist(clusterDetailsVO);
                } else {
                    clusterDetailsVO.setValue(value);
                    _clusterDetailsDao.update(clusterDetailsVO.getId(), clusterDetailsVO);
                }
                break;
            case StoragePool:
                final StoragePoolVO pool = _storagePoolDao.findById(resourceId);
                if (pool == null) {
                    throw new InvalidParameterValueException("unable to find storage pool by id " + resourceId);
                }
                if (name.equals(CapacityManager.StorageOverprovisioningFactor.key())) {
                    if (pool.getPoolType() != StoragePoolType.NetworkFilesystem) {
                        throw new InvalidParameterValueException("Unable to update  storage pool with id " + resourceId + ". Overprovision not supported for " + pool.getPoolType());
                    }
                }
                _storagePoolDetailsDao.addDetail(resourceId, name, value, true);
                break;
            case Account:
                final AccountVO account = _accountDao.findById(resourceId);
                if (account == null) {
                    throw new InvalidParameterValueException("unable to find account by id " + resourceId);
                }
                AccountDetailVO accountDetailVO = _accountDetailsDao.findDetail(resourceId, name);
                if (accountDetailVO == null) {
                    accountDetailVO = new AccountDetailVO(resourceId, name, value);
                    _accountDetailsDao.persist(accountDetailVO);
                } else {
                    accountDetailVO.setValue(value);
                    _accountDetailsDao.update(accountDetailVO.getId(), accountDetailVO);
                }
                break;
            default:
                throw new InvalidParameterValueException("Scope provided is invalid");
        }
        return value;
    }
    // Execute all updates in a single transaction
    final TransactionLegacy txn = TransactionLegacy.currentTxn();
    txn.start();
    if (!_configDao.update(name, category, value)) {
        s_logger.error("Failed to update configuration option, name: " + name + ", value:" + value);
        throw new CloudRuntimeException("Failed to update configuration value. Please contact Cloud Support.");
    }
    PreparedStatement pstmt;
    if (Config.XenServerGuestNetwork.key().equalsIgnoreCase(name)) {
        final String sql = "update host_details set value=? where name=?";
        try {
            pstmt = txn.prepareAutoCloseStatement(sql);
            pstmt.setString(1, value);
            pstmt.setString(2, "guest.network.device");
            pstmt.executeUpdate();
        } catch (final SQLException e) {
            throw new CloudRuntimeException("Failed to update guest.network.device in host_details due to exception ", e);
        }
    } else if (Config.XenServerPrivateNetwork.key().equalsIgnoreCase(name)) {
        final String sql = "update host_details set value=? where name=?";
        try {
            pstmt = txn.prepareAutoCloseStatement(sql);
            pstmt.setString(1, value);
            pstmt.setString(2, "private.network.device");
            pstmt.executeUpdate();
        } catch (final SQLException e) {
            throw new CloudRuntimeException("Failed to update private.network.device in host_details due to exception ", e);
        }
    } else if (Config.XenServerPublicNetwork.key().equalsIgnoreCase(name)) {
        final String sql = "update host_details set value=? where name=?";
        try {
            pstmt = txn.prepareAutoCloseStatement(sql);
            pstmt.setString(1, value);
            pstmt.setString(2, "public.network.device");
            pstmt.executeUpdate();
        } catch (final SQLException e) {
            throw new CloudRuntimeException("Failed to update public.network.device in host_details due to exception ", e);
        }
    } else if (Config.XenServerStorageNetwork1.key().equalsIgnoreCase(name)) {
        final String sql = "update host_details set value=? where name=?";
        try {
            pstmt = txn.prepareAutoCloseStatement(sql);
            pstmt.setString(1, value);
            pstmt.setString(2, "storage.network.device1");
            pstmt.executeUpdate();
        } catch (final SQLException e) {
            throw new CloudRuntimeException("Failed to update storage.network.device1 in host_details due to exception ", e);
        }
    } else if (Config.XenServerStorageNetwork2.key().equals(name)) {
        final String sql = "update host_details set value=? where name=?";
        try {
            pstmt = txn.prepareAutoCloseStatement(sql);
            pstmt.setString(1, value);
            pstmt.setString(2, "storage.network.device2");
            pstmt.executeUpdate();
        } catch (final SQLException e) {
            throw new CloudRuntimeException("Failed to update storage.network.device2 in host_details due to exception ", e);
        }
    } else if (Config.SecStorageSecureCopyCert.key().equalsIgnoreCase(name)) {
        // FIXME - Ideally there should be a listener model to listen to global config changes and be able to take action gracefully.
        // Expire the download urls
        final String sqlTemplate = "update template_store_ref set download_url_created=?";
        final String sqlVolume = "update volume_store_ref set download_url_created=?";
        try {
            // Change for templates
            pstmt = txn.prepareAutoCloseStatement(sqlTemplate);
            // Set the time before the epoch time.
            pstmt.setDate(1, new Date(-1l));
            pstmt.executeUpdate();
            // Change for volumes
            pstmt = txn.prepareAutoCloseStatement(sqlVolume);
            // Set the time before the epoch time.
            pstmt.setDate(1, new Date(-1l));
            pstmt.executeUpdate();
            // Cleanup the download urls
            _storageManager.cleanupDownloadUrls();
        } catch (final SQLException e) {
            throw new CloudRuntimeException("Failed to clean up download URLs in template_store_ref or volume_store_ref due to exception ", e);
        }
    }
    txn.commit();
    return _configDao.getValue(name);
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) ClusterVO(com.cloud.dc.ClusterVO) SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement) AccountVO(com.cloud.user.AccountVO) Date(java.sql.Date) TransactionLegacy(com.cloud.utils.db.TransactionLegacy) AccountDetailVO(com.cloud.user.AccountDetailVO) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) StoragePoolVO(com.cloud.storage.datastore.db.StoragePoolVO) ClusterDetailsVO(com.cloud.dc.ClusterDetailsVO) DB(com.cloud.utils.db.DB)

Aggregations

StoragePoolVO (com.cloud.storage.datastore.db.StoragePoolVO)86 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)29 InvalidParameterValueException (com.cloud.utils.exception.InvalidParameterValueException)22 Test (org.junit.Test)18 HostVO (com.cloud.host.HostVO)15 VolumeVO (com.cloud.storage.VolumeVO)15 ArrayList (java.util.ArrayList)15 Answer (com.cloud.agent.api.Answer)14 Account (com.cloud.user.Account)13 DataStore (com.cloud.engine.subsystem.api.storage.DataStore)12 StorageUnavailableException (com.cloud.exception.StorageUnavailableException)11 StoragePool (com.cloud.storage.StoragePool)10 AttachAnswer (com.cloud.storage.command.AttachAnswer)10 VolumeInfo (com.cloud.engine.subsystem.api.storage.VolumeInfo)9 VMInstanceVO (com.cloud.vm.VMInstanceVO)9 RebootAnswer (com.cloud.agent.api.RebootAnswer)8 PrimaryDataStore (com.cloud.engine.subsystem.api.storage.PrimaryDataStore)8 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)8 PermissionDeniedException (com.cloud.exception.PermissionDeniedException)8 VMTemplateStoragePoolVO (com.cloud.storage.VMTemplateStoragePoolVO)8