Search in sources :

Example 1 with SnapshotDetailsVO

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);
}
Also used : VMInstanceVO(com.cloud.vm.VMInstanceVO) SnapshotDetailsVO(com.cloud.storage.dao.SnapshotDetailsVO) HostVO(com.cloud.host.HostVO) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) VolumeVO(com.cloud.storage.VolumeVO) SnapshotAndCopyAnswer(com.cloud.storage.command.SnapshotAndCopyAnswer) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) DataStore(com.cloud.engine.subsystem.api.storage.DataStore) StoragePoolVO(com.cloud.storage.datastore.db.StoragePoolVO) SnapshotAndCopyCommand(com.cloud.storage.command.SnapshotAndCopyCommand)

Example 2 with SnapshotDetailsVO

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);
}
Also used : SnapshotDetailsVO(com.cloud.storage.dao.SnapshotDetailsVO)

Example 3 with SnapshotDetailsVO

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;
}
Also used : SnapshotInfo(org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo) VMSnapshotVO(com.cloud.vm.snapshot.VMSnapshotVO) SnapshotVO(com.cloud.storage.SnapshotVO) SnapshotResult(org.apache.cloudstack.engine.subsystem.api.storage.SnapshotResult) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) VolumeInfo(org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo) SnapshotDetailsVO(com.cloud.storage.dao.SnapshotDetailsVO) VMSnapshot(com.cloud.vm.snapshot.VMSnapshot) HostVO(com.cloud.host.HostVO) DB(com.cloud.utils.db.DB)

Example 4 with SnapshotDetailsVO

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);
}
Also used : SnapshotDetailsVO(com.cloud.storage.dao.SnapshotDetailsVO)

Example 5 with SnapshotDetailsVO

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);
}
Also used : SnapshotDetailsVO(com.cloud.storage.dao.SnapshotDetailsVO)

Aggregations

SnapshotDetailsVO (com.cloud.storage.dao.SnapshotDetailsVO)33 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)21 SnapshotVO (com.cloud.storage.SnapshotVO)7 VolumeVO (com.cloud.storage.VolumeVO)7 VMTemplateStoragePoolVO (com.cloud.storage.VMTemplateStoragePoolVO)6 DateraObject (org.apache.cloudstack.storage.datastore.util.DateraObject)5 SolidFireUtil (org.apache.cloudstack.storage.datastore.util.SolidFireUtil)5 VolumeInfo (org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo)4 StoragePoolVO (org.apache.cloudstack.storage.datastore.db.StoragePoolVO)4 HostVO (com.cloud.host.HostVO)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 NoTransitionException (com.cloud.utils.fsm.NoTransitionException)2 VMInstanceVO (com.cloud.vm.VMInstanceVO)2 ArrayList (java.util.ArrayList)2 CopyCommandResult (org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult)2 CommandResult (org.apache.cloudstack.storage.command.CommandResult)2 DataStore (com.cloud.engine.subsystem.api.storage.DataStore)1 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)1 VolumeDetailVO (com.cloud.storage.VolumeDetailVO)1 SnapshotAndCopyAnswer (com.cloud.storage.command.SnapshotAndCopyAnswer)1