use of com.cloud.storage.command.SnapshotAndCopyAnswer 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.command.SnapshotAndCopyAnswer in project cosmic by MissionCriticalCloud.
the class XenServerStorageProcessor method snapshotAndCopy.
// if the source SR needs to be attached to, do so
// take a snapshot of the source VDI (on the source SR)
// create an iSCSI SR based on the new back-end volume
// copy the snapshot to the new SR
// delete the snapshot
// detach the new SR
// if we needed to perform an attach to the source SR, detach from it
@Override
public SnapshotAndCopyAnswer snapshotAndCopy(final SnapshotAndCopyCommand cmd) {
final Connection conn = hypervisorResource.getConnection();
try {
SR sourceSr = null;
final Map<String, String> sourceDetails = cmd.getSourceDetails();
if (sourceDetails != null && sourceDetails.keySet().size() > 0) {
final String iScsiName = sourceDetails.get(DiskTO.IQN);
final String storageHost = sourceDetails.get(DiskTO.STORAGE_HOST);
final String chapInitiatorUsername = sourceDetails.get(DiskTO.CHAP_INITIATOR_USERNAME);
final String chapInitiatorSecret = sourceDetails.get(DiskTO.CHAP_INITIATOR_SECRET);
sourceSr = hypervisorResource.getIscsiSR(conn, iScsiName, storageHost, iScsiName, chapInitiatorUsername, chapInitiatorSecret, false);
}
final VDI vdiToSnapshot = VDI.getByUuid(conn, cmd.getUuidOfSourceVdi());
final VDI vdiSnapshot = vdiToSnapshot.snapshot(conn, new HashMap<>());
final Map<String, String> destDetails = cmd.getDestDetails();
final String iScsiName = destDetails.get(DiskTO.IQN);
final String storageHost = destDetails.get(DiskTO.STORAGE_HOST);
final String chapInitiatorUsername = destDetails.get(DiskTO.CHAP_INITIATOR_USERNAME);
final String chapInitiatorSecret = destDetails.get(DiskTO.CHAP_INITIATOR_SECRET);
final SR newSr = hypervisorResource.getIscsiSR(conn, iScsiName, storageHost, iScsiName, chapInitiatorUsername, chapInitiatorSecret, false);
final VDI vdiCopy = vdiSnapshot.copy(conn, newSr);
final String vdiUuid = vdiCopy.getUuid(conn);
vdiSnapshot.destroy(conn);
if (sourceSr != null) {
hypervisorResource.removeSR(conn, sourceSr);
}
hypervisorResource.removeSR(conn, newSr);
final SnapshotAndCopyAnswer snapshotAndCopyAnswer = new SnapshotAndCopyAnswer();
snapshotAndCopyAnswer.setPath(vdiUuid);
return snapshotAndCopyAnswer;
} catch (final Exception ex) {
s_logger.warn("Failed to take and copy snapshot: " + ex.toString(), ex);
return new SnapshotAndCopyAnswer(ex.getMessage());
}
}
Aggregations