use of org.apache.cloudstack.storage.datastore.db.StoragePoolVO in project cloudstack by apache.
the class SolidFirePrimaryDataStoreDriver method verifySufficientBytesForStoragePool.
private void verifySufficientBytesForStoragePool(long requestedBytes, long storagePoolId) {
StoragePoolVO storagePool = storagePoolDao.findById(storagePoolId);
long capacityBytes = storagePool.getCapacityBytes();
long usedBytes = getUsedBytes(storagePool);
usedBytes += requestedBytes;
if (usedBytes > capacityBytes) {
throw new CloudRuntimeException("Insufficient amount of space remains in this primary storage");
}
}
use of org.apache.cloudstack.storage.datastore.db.StoragePoolVO in project cloudstack by apache.
the class SolidFirePrimaryDataStoreDriver method verifySufficientBytesForStoragePool.
private void verifySufficientBytesForStoragePool(DataObject dataObject, long storagePoolId) {
StoragePoolVO storagePool = storagePoolDao.findById(storagePoolId);
long requestedBytes = getDataObjectSizeIncludingHypervisorSnapshotReserve(dataObject, storagePool);
verifySufficientBytesForStoragePool(requestedBytes, storagePoolId);
}
use of org.apache.cloudstack.storage.datastore.db.StoragePoolVO in project cloudstack by apache.
the class SolidFirePrimaryDataStoreDriver method deleteTemplate.
private void deleteTemplate(TemplateInfo template, long storagePoolId) {
try {
SolidFireUtil.SolidFireConnection sfConnection = SolidFireUtil.getSolidFireConnection(storagePoolId, storagePoolDetailsDao);
long sfTemplateVolumeId = getVolumeIdFrom_iScsiPath(template.getInstallPath());
SolidFireUtil.deleteVolume(sfConnection, sfTemplateVolumeId);
StoragePoolVO storagePool = storagePoolDao.findById(storagePoolId);
// getUsedBytes(StoragePool) will not include the template to delete because the "template_spool_ref" table has already been updated by this point
long usedBytes = getUsedBytes(storagePool);
storagePool.setUsedBytes(usedBytes < 0 ? 0 : usedBytes);
storagePoolDao.update(storagePoolId, storagePool);
} catch (Exception ex) {
LOGGER.debug(SolidFireUtil.LOG_PREFIX + "Failed to delete SolidFire template volume. CloudStack template ID: " + template.getId(), ex);
throw ex;
}
}
use of org.apache.cloudstack.storage.datastore.db.StoragePoolVO in project cloudstack by apache.
the class ScaleIOPrimaryDataStoreDriver method deleteAsync.
@Override
public void deleteAsync(DataStore dataStore, DataObject dataObject, AsyncCompletionCallback<CommandResult> callback) {
Preconditions.checkArgument(dataObject != null, "dataObject cannot be null");
long storagePoolId = dataStore.getId();
StoragePoolVO storagePool = storagePoolDao.findById(storagePoolId);
Preconditions.checkArgument(storagePoolId > 0, "storagePoolId should be > 0");
Preconditions.checkArgument(storagePool != null && storagePool.getHostAddress() != null, "storagePool and host address should not be null");
String errMsg = null;
String scaleIOVolumePath = null;
try {
boolean deleteResult = false;
if (dataObject.getType() == DataObjectType.VOLUME) {
LOGGER.debug("deleteAsync - deleting volume");
scaleIOVolumePath = ((VolumeInfo) dataObject).getPath();
} else if (dataObject.getType() == DataObjectType.SNAPSHOT) {
LOGGER.debug("deleteAsync - deleting snapshot");
scaleIOVolumePath = ((SnapshotInfo) dataObject).getPath();
} else if (dataObject.getType() == DataObjectType.TEMPLATE) {
LOGGER.debug("deleteAsync - deleting template");
scaleIOVolumePath = ((TemplateInfo) dataObject).getInstallPath();
} else {
errMsg = "Invalid DataObjectType (" + dataObject.getType() + ") passed to deleteAsync";
LOGGER.error(errMsg);
throw new CloudRuntimeException(errMsg);
}
try {
String scaleIOVolumeId = ScaleIOUtil.getVolumePath(scaleIOVolumePath);
final ScaleIOGatewayClient client = getScaleIOClient(storagePoolId);
deleteResult = client.deleteVolume(scaleIOVolumeId);
if (!deleteResult) {
errMsg = "Failed to delete PowerFlex volume with id: " + scaleIOVolumeId;
}
long usedBytes = storagePool.getUsedBytes();
usedBytes -= dataObject.getSize();
storagePool.setUsedBytes(usedBytes < 0 ? 0 : usedBytes);
storagePoolDao.update(storagePoolId, storagePool);
} catch (Exception e) {
errMsg = "Unable to delete PowerFlex volume: " + scaleIOVolumePath + " due to " + e.getMessage();
LOGGER.warn(errMsg);
throw new CloudRuntimeException(errMsg, e);
}
} catch (Exception ex) {
errMsg = ex.getMessage();
LOGGER.error(errMsg);
if (callback == null) {
throw ex;
}
}
if (callback != null) {
CommandResult result = new CommandResult();
result.setResult(errMsg);
callback.complete(result);
}
}
use of org.apache.cloudstack.storage.datastore.db.StoragePoolVO in project cloudstack by apache.
the class VirtualMachineManagerImpl method getVolumesToDisconnect.
private List<Map<String, String>> getVolumesToDisconnect(VirtualMachine vm) {
List<Map<String, String>> volumesToDisconnect = new ArrayList<>();
List<VolumeVO> volumes = _volsDao.findByInstance(vm.getId());
if (CollectionUtils.isEmpty(volumes)) {
return volumesToDisconnect;
}
for (VolumeVO volume : volumes) {
StoragePoolVO storagePool = _storagePoolDao.findById(volume.getPoolId());
if (storagePool != null && storagePool.isManaged()) {
Map<String, String> info = new HashMap<>();
info.put(DiskTO.STORAGE_HOST, storagePool.getHostAddress());
info.put(DiskTO.STORAGE_PORT, String.valueOf(storagePool.getPort()));
info.put(DiskTO.IQN, volume.get_iScsiName());
info.put(DiskTO.PROTOCOL_TYPE, (volume.getPoolType() != null) ? volume.getPoolType().toString() : null);
volumesToDisconnect.add(info);
}
}
return volumesToDisconnect;
}
Aggregations