use of com.cloud.storage.dao.SnapshotDetailsVO in project cloudstack by apache.
the class DateraPrimaryDataStoreDriver method getUsedBytes.
/**
* Get the total space used by all the entities on the storage.
* Total space = volume space + snapshot space + template space
* @param storagePool Primary storage
* @param volumeIdToIgnore Ignore this volume (used when we delete a volume and
* want to update the space)
* @return size in bytes
*/
private long getUsedBytes(StoragePool storagePool, long volumeIdToIgnore) {
long usedSpaceBytes = 0;
List<VolumeVO> lstVolumes = _volumeDao.findByPoolId(storagePool.getId(), null);
if (lstVolumes != null) {
for (VolumeVO volume : lstVolumes) {
if (volume.getId() == volumeIdToIgnore) {
continue;
}
VolumeDetailVO volumeDetail = volumeDetailsDao.findDetail(volume.getId(), DateraUtil.VOLUME_SIZE);
if (volumeDetail != null && volumeDetail.getValue() != null) {
long volumeSizeGib = Long.parseLong(volumeDetail.getValue());
long volumeSizeBytes = DateraUtil.gibToBytes((int) (volumeSizeGib));
usedSpaceBytes += volumeSizeBytes;
} else {
DateraObject.DateraConnection conn = DateraUtil.getDateraConnection(storagePool.getId(), _storagePoolDetailsDao);
try {
String appInstanceName = getAppInstanceName(volumeDataFactory.getVolume(volume.getId()));
DateraObject.AppInstance appInstance = DateraUtil.getAppInstance(conn, appInstanceName);
if (appInstance != null) {
usedSpaceBytes += DateraUtil.gibToBytes(appInstance.getSize());
}
} catch (DateraObject.DateraError dateraError) {
String errMesg = "Error getting used bytes for storage pool : " + storagePool.getId();
s_logger.warn(errMesg, dateraError);
throw new CloudRuntimeException(errMesg);
}
}
}
}
List<SnapshotVO> lstSnapshots = _snapshotDao.listAll();
if (lstSnapshots != null) {
for (SnapshotVO snapshot : lstSnapshots) {
SnapshotDetailsVO snapshotDetails = _snapshotDetailsDao.findDetail(snapshot.getId(), DateraUtil.STORAGE_POOL_ID);
// if this snapshot belongs to the storagePool that was passed in
if (snapshotDetails != null && snapshotDetails.getValue() != null && Long.parseLong(snapshotDetails.getValue()) == storagePool.getId()) {
snapshotDetails = _snapshotDetailsDao.findDetail(snapshot.getId(), DateraUtil.VOLUME_SIZE);
if (snapshotDetails != null && snapshotDetails.getValue() != null) {
long snapshotSize = Long.parseLong(snapshotDetails.getValue());
usedSpaceBytes += snapshotSize;
}
}
}
}
List<VMTemplateStoragePoolVO> lstTemplatePoolRefs = tmpltPoolDao.listByPoolId(storagePool.getId());
if (lstTemplatePoolRefs != null) {
for (VMTemplateStoragePoolVO templatePoolRef : lstTemplatePoolRefs) {
usedSpaceBytes += templatePoolRef.getTemplateSize();
}
}
s_logger.debug("usedSpaceBytes: " + toHumanReadableSize(usedSpaceBytes));
return usedSpaceBytes;
}
use of com.cloud.storage.dao.SnapshotDetailsVO in project cloudstack by apache.
the class SolidFirePrimaryDataStoreDriver method deleteSnapshot.
private void deleteSnapshot(SnapshotInfo snapshotInfo, long storagePoolId) {
long csSnapshotId = snapshotInfo.getId();
try {
SolidFireUtil.SolidFireConnection sfConnection = SolidFireUtil.getSolidFireConnection(storagePoolId, storagePoolDetailsDao);
SnapshotDetailsVO snapshotDetails = snapshotDetailsDao.findDetail(csSnapshotId, SolidFireUtil.SNAPSHOT_ID);
if (snapshotDetails != null && snapshotDetails.getValue() != null) {
// A SolidFire snapshot is being used to support the CloudStack volume snapshot.
long sfSnapshotId = Long.parseLong(snapshotDetails.getValue());
deleteSolidFireSnapshot(sfConnection, csSnapshotId, sfSnapshotId);
} else {
// A SolidFire volume is being used to support the CloudStack volume snapshot.
snapshotDetails = snapshotDetailsDao.findDetail(csSnapshotId, SolidFireUtil.VOLUME_ID);
long sfVolumeId = Long.parseLong(snapshotDetails.getValue());
SolidFireUtil.deleteVolume(sfConnection, sfVolumeId);
}
snapshotDetailsDao.removeDetails(csSnapshotId);
StoragePoolVO storagePool = storagePoolDao.findById(storagePoolId);
// getUsedBytes(StoragePool) will not include the snapshot to delete because it has already been deleted 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 + "Issue in 'deleteSnapshot(SnapshotInfo, long)'. CloudStack snapshot ID: " + csSnapshotId, ex);
throw ex;
}
}
use of com.cloud.storage.dao.SnapshotDetailsVO in project cloudstack by apache.
the class SolidFirePrimaryDataStoreDriver method createClone.
private SolidFireUtil.SolidFireVolume createClone(SolidFireUtil.SolidFireConnection sfConnection, long dataObjectId, VolumeInfo volumeInfo, long sfAccountId, long storagePoolId, DataObjectType dataObjectType) {
String sfNewVolumeName = volumeInfo.getName();
long sfVolumeId = Long.MIN_VALUE;
long sfSnapshotId = Long.MIN_VALUE;
if (dataObjectType == DataObjectType.SNAPSHOT) {
SnapshotDetailsVO snapshotDetails = snapshotDetailsDao.findDetail(dataObjectId, SolidFireUtil.SNAPSHOT_ID);
if (snapshotDetails != null && snapshotDetails.getValue() != null) {
sfSnapshotId = Long.parseLong(snapshotDetails.getValue());
}
snapshotDetails = snapshotDetailsDao.findDetail(dataObjectId, SolidFireUtil.VOLUME_ID);
sfVolumeId = Long.parseLong(snapshotDetails.getValue());
} else if (dataObjectType == DataObjectType.TEMPLATE) {
// get the cached template on this storage
VMTemplateStoragePoolVO templatePoolRef = vmTemplatePoolDao.findByPoolTemplate(storagePoolId, dataObjectId, null);
if (templatePoolRef != null) {
sfVolumeId = Long.parseLong(templatePoolRef.getLocalDownloadPath());
}
}
if (sfVolumeId <= 0) {
throw new CloudRuntimeException("Unable to find SolidFire volume for the following data-object ID: " + dataObjectId + " and data-object type: " + dataObjectType);
}
final long newSfVolumeId = SolidFireUtil.createClone(sfConnection, sfVolumeId, sfSnapshotId, sfAccountId, SolidFireUtil.getSolidFireVolumeName(sfNewVolumeName), getVolumeAttributes(volumeInfo));
final Iops iops = getIops(volumeInfo.getMinIops(), volumeInfo.getMaxIops(), storagePoolId);
SolidFireUtil.modifyVolume(sfConnection, newSfVolumeId, null, null, iops.getMinIops(), iops.getMaxIops(), iops.getBurstIops());
return SolidFireUtil.getVolume(sfConnection, newSfVolumeId);
}
use of com.cloud.storage.dao.SnapshotDetailsVO in project cloudstack by apache.
the class SolidFirePrimaryDataStoreDriver method removeTempVolumeId.
private void removeTempVolumeId(long csSnapshotId) {
SnapshotDetailsVO snapshotDetails = snapshotDetailsDao.findDetail(csSnapshotId, SolidFireUtil.TEMP_VOLUME_ID);
if (snapshotDetails == null || snapshotDetails.getValue() == null) {
throw new CloudRuntimeException("'removeTempVolumeId' should not be invoked unless " + SolidFireUtil.TEMP_VOLUME_ID + " exists.");
}
String originalVolumeId = snapshotDetails.getValue();
handleSnapshotDetails(csSnapshotId, SolidFireUtil.VOLUME_ID, originalVolumeId);
snapshotDetailsDao.remove(snapshotDetails.getId());
}
use of com.cloud.storage.dao.SnapshotDetailsVO in project cloudstack by apache.
the class SolidFirePrimaryDataStoreDriver method deleteSolidFireVolume.
private void deleteSolidFireVolume(SolidFireUtil.SolidFireConnection sfConnection, long csVolumeId, long sfVolumeId) {
List<SnapshotVO> lstSnapshots = getNonDestroyedSnapshots(csVolumeId);
boolean deleteVolume = true;
for (SnapshotVO snapshot : lstSnapshots) {
SnapshotDetailsVO snapshotDetails = snapshotDetailsDao.findDetail(snapshot.getId(), SolidFireUtil.SNAPSHOT_ID);
if (snapshotDetails != null && snapshotDetails.getValue() != null) {
deleteVolume = false;
break;
}
}
if (deleteVolume) {
SolidFireUtil.deleteVolume(sfConnection, sfVolumeId);
}
}
Aggregations