use of com.cloud.storage.dao.SnapshotDetailsVO in project cosmic by MissionCriticalCloud.
the class StorageSystemSnapshotStrategy method performSnapshotAndCopyOnHostSide.
private void performSnapshotAndCopyOnHostSide(final VolumeInfo volumeInfo, final SnapshotInfo snapshotInfo) {
Map<String, String> sourceDetails = null;
final VolumeVO volumeVO = _volumeDao.findById(volumeInfo.getId());
final Long vmInstanceId = volumeVO.getInstanceId();
final VMInstanceVO vmInstanceVO = _vmInstanceDao.findById(vmInstanceId);
Long hostId = null;
// if the volume to snapshot is associated with a VM
if (vmInstanceVO != null) {
hostId = vmInstanceVO.getHostId();
// if the VM is not associated with a host
if (hostId == null) {
hostId = vmInstanceVO.getLastHostId();
if (hostId == null) {
sourceDetails = getSourceDetails(volumeInfo);
}
}
} else // volume to snapshot is not associated with a VM (could be a data disk in the detached state)
{
sourceDetails = getSourceDetails(volumeInfo);
}
final HostVO hostVO = getHost(hostId, volumeVO);
final long storagePoolId = volumeVO.getPoolId();
final StoragePoolVO storagePoolVO = _storagePoolDao.findById(storagePoolId);
final DataStore dataStore = _dataStoreMgr.getDataStore(storagePoolId, DataStoreRole.Primary);
final Map<String, String> destDetails = getDestDetails(storagePoolVO, snapshotInfo);
final SnapshotAndCopyCommand snapshotAndCopyCommand = new SnapshotAndCopyCommand(volumeInfo.getPath(), sourceDetails, destDetails);
SnapshotAndCopyAnswer snapshotAndCopyAnswer = null;
try {
// if sourceDetails != null, we need to connect the host(s) to the volume
if (sourceDetails != null) {
_volService.grantAccess(volumeInfo, hostVO, dataStore);
}
_volService.grantAccess(snapshotInfo, hostVO, dataStore);
snapshotAndCopyAnswer = (SnapshotAndCopyAnswer) _agentMgr.send(hostVO.getId(), snapshotAndCopyCommand);
} catch (final Exception ex) {
throw new CloudRuntimeException(ex.getMessage());
} finally {
try {
_volService.revokeAccess(snapshotInfo, hostVO, dataStore);
// if sourceDetails != null, we need to disconnect the host(s) from the volume
if (sourceDetails != null) {
_volService.revokeAccess(volumeInfo, hostVO, dataStore);
}
} catch (final Exception ex) {
s_logger.debug(ex.getMessage(), ex);
}
}
if (snapshotAndCopyAnswer == null || !snapshotAndCopyAnswer.getResult()) {
final String errMsg;
if (snapshotAndCopyAnswer != null && snapshotAndCopyAnswer.getDetails() != null && !snapshotAndCopyAnswer.getDetails().isEmpty()) {
errMsg = snapshotAndCopyAnswer.getDetails();
} else {
errMsg = "Unable to perform host-side operation";
}
throw new CloudRuntimeException(errMsg);
}
// for XenServer, this is the VDI's UUID
final String path = snapshotAndCopyAnswer.getPath();
final SnapshotDetailsVO snapshotDetail = new SnapshotDetailsVO(snapshotInfo.getId(), DiskTO.PATH, path, false);
_snapshotDetailsDao.persist(snapshotDetail);
}
use of com.cloud.storage.dao.SnapshotDetailsVO in project cloudstack by apache.
the class StorageSystemSnapshotStrategy method setVmdk.
private void setVmdk(SnapshotInfo snapshotInfo, VolumeInfo volumeInfo) {
if (!ImageFormat.OVA.equals(volumeInfo.getFormat())) {
return;
}
String search = "]";
String path = volumeInfo.getPath();
int startIndex = path.indexOf(search);
SnapshotDetailsVO snapshotDetail = new SnapshotDetailsVO(snapshotInfo.getId(), DiskTO.VMDK, path.substring(startIndex + search.length()).trim(), false);
snapshotDetailsDao.persist(snapshotDetail);
}
use of com.cloud.storage.dao.SnapshotDetailsVO in project cloudstack by apache.
the class StorageSystemSnapshotStrategy method takeSnapshot.
@Override
@DB
public SnapshotInfo takeSnapshot(SnapshotInfo snapshotInfo) {
VolumeInfo volumeInfo = snapshotInfo.getBaseVolume();
verifyFormat(volumeInfo);
verifyLocationType(snapshotInfo);
final boolean canStorageSystemCreateVolumeFromSnapshot = canStorageSystemCreateVolumeFromSnapshot(volumeInfo.getPoolId());
final boolean computeClusterSupportsVolumeClone;
// only XenServer, VMware and KVM are currently supported
if (volumeInfo.getFormat() == ImageFormat.VHD) {
HostVO hostVO = getHost(volumeInfo.getId());
computeClusterSupportsVolumeClone = clusterDao.getSupportsResigning(hostVO.getClusterId());
} else if (volumeInfo.getFormat() == ImageFormat.OVA || volumeInfo.getFormat() == ImageFormat.QCOW2 || volumeInfo.getFormat() == ImageFormat.RAW) {
computeClusterSupportsVolumeClone = true;
} else {
throw new CloudRuntimeException("Unsupported format");
}
SnapshotVO snapshotVO = snapshotDao.acquireInLockTable(snapshotInfo.getId());
if (snapshotVO == null) {
throw new CloudRuntimeException("Failed to acquire lock on the following snapshot: " + snapshotInfo.getId());
}
VMSnapshot vmSnapshot = null;
if (ImageFormat.OVA.equals(volumeInfo.getFormat())) {
setVmdk(snapshotInfo, volumeInfo);
vmSnapshot = takeHypervisorSnapshot(volumeInfo);
}
SnapshotResult result = null;
SnapshotInfo snapshotOnPrimary;
try {
volumeInfo.stateTransit(Volume.Event.SnapshotRequested);
if (canStorageSystemCreateVolumeFromSnapshot && computeClusterSupportsVolumeClone) {
SnapshotDetailsVO snapshotDetail = new SnapshotDetailsVO(snapshotInfo.getId(), "takeSnapshot", Boolean.TRUE.toString(), false);
snapshotDetailsDao.persist(snapshotDetail);
}
result = snapshotSvr.takeSnapshot(snapshotInfo);
if (result.isFailed()) {
s_logger.debug("Failed to take a snapshot: " + result.getResult());
throw new CloudRuntimeException(result.getResult());
}
if (!canStorageSystemCreateVolumeFromSnapshot || !computeClusterSupportsVolumeClone) {
performSnapshotAndCopyOnHostSide(volumeInfo, snapshotInfo);
}
snapshotOnPrimary = result.getSnapshot();
} finally {
if (result != null && result.isSuccess()) {
volumeInfo.stateTransit(Volume.Event.OperationSucceeded);
} else {
volumeInfo.stateTransit(Volume.Event.OperationFailed);
}
if (ImageFormat.OVA.equals(volumeInfo.getFormat())) {
if (vmSnapshot != null) {
deleteHypervisorSnapshot(vmSnapshot);
}
}
}
snapshotDao.releaseFromLockTable(snapshotInfo.getId());
return snapshotOnPrimary;
}
use of com.cloud.storage.dao.SnapshotDetailsVO in project cloudstack by apache.
the class DateraPrimaryDataStoreDriver method handleSnapshotDetails.
/**
* Helper function to update snapshot_details table
*
* @param csSnapshotId Snapshot
* @param name attribute name
* @param value attribute value
*/
private void handleSnapshotDetails(long csSnapshotId, String name, String value) {
snapshotDetailsDao.removeDetail(csSnapshotId, name);
SnapshotDetailsVO snapshotDetails = new SnapshotDetailsVO(csSnapshotId, name, value, false);
snapshotDetailsDao.persist(snapshotDetails);
}
use of com.cloud.storage.dao.SnapshotDetailsVO in project cloudstack by apache.
the class DateraPrimaryDataStoreDriver method updateSnapshotDetails.
/**
* If a native snapshot is used, this function updates the snapshot_detauls
* table with the correct attributes
*
* @param csSnapshotId Cloudstack snapshot ID
* @param volumeId Base volume ID
* @param newSnapshotId SnapshotID on Datera (appInstanceName:Timestamp)
* @param storagePoolId Primary storage
* @param newVolumeSize VolumeSize in GB
*/
private void updateSnapshotDetails(long csSnapshotId, String volumeId, String newSnapshotId, long storagePoolId, long newVolumeSize) {
SnapshotDetailsVO snapshotDetail = new SnapshotDetailsVO(csSnapshotId, DateraUtil.VOLUME_ID, String.valueOf(volumeId), false);
snapshotDetailsDao.persist(snapshotDetail);
snapshotDetail = new SnapshotDetailsVO(csSnapshotId, DateraUtil.SNAPSHOT_ID, String.valueOf(newSnapshotId), false);
snapshotDetailsDao.persist(snapshotDetail);
snapshotDetail = new SnapshotDetailsVO(csSnapshotId, DateraUtil.STORAGE_POOL_ID, String.valueOf(storagePoolId), false);
snapshotDetailsDao.persist(snapshotDetail);
snapshotDetail = new SnapshotDetailsVO(csSnapshotId, DateraUtil.VOLUME_SIZE, String.valueOf(newVolumeSize), false);
snapshotDetailsDao.persist(snapshotDetail);
}
Aggregations