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;
}
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;
}
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);
}
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();
}
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);
}
Aggregations