Search in sources :

Example 21 with SnapshotDetailsVO

use of com.cloud.storage.dao.SnapshotDetailsVO in project cloudstack by apache.

the class SolidFirePrimaryDataStoreDriver method getSolidFireVolumeId.

private long getSolidFireVolumeId(DataObject dataObject, boolean grantAccess) {
    if (dataObject.getType() == DataObjectType.VOLUME) {
        final VolumeInfo volumeInfo = (VolumeInfo) dataObject;
        final long volumeId = volumeInfo.getId();
        if (grantAccess && isBasicGrantAccess(volumeId)) {
            volumeDetailsDao.removeDetail(volumeInfo.getId(), BASIC_GRANT_ACCESS);
            final Long sfVolumeId = getBasicSfVolumeId(volumeId);
            Preconditions.checkNotNull(sfVolumeId, "'sfVolumeId' should not be 'null' (basic grant access).");
            return sfVolumeId;
        } else if (!grantAccess && isBasicRevokeAccess(volumeId)) {
            volumeDetailsDao.removeDetail(volumeInfo.getId(), BASIC_REVOKE_ACCESS);
            final Long sfVolumeId = getBasicSfVolumeId(volumeId);
            Preconditions.checkNotNull(sfVolumeId, "'sfVolumeId' should not be 'null' (basic revoke access).");
            return sfVolumeId;
        }
        return Long.parseLong(volumeInfo.getFolder());
    }
    if (dataObject.getType() == DataObjectType.SNAPSHOT) {
        SnapshotDetailsVO snapshotDetails = snapshotDetailsDao.findDetail(dataObject.getId(), SolidFireUtil.VOLUME_ID);
        if (snapshotDetails == null || snapshotDetails.getValue() == null) {
            throw new CloudRuntimeException("Unable to locate the volume ID associated with the following snapshot ID: " + dataObject.getId());
        }
        return Long.parseLong(snapshotDetails.getValue());
    }
    if (dataObject.getType() == DataObjectType.TEMPLATE) {
        return getVolumeIdFrom_iScsiPath(((TemplateInfo) dataObject).getInstallPath());
    }
    throw new CloudRuntimeException("Invalid DataObjectType (" + dataObject.getType() + ") passed to getSolidFireVolumeId(DataObject, boolean)");
}
Also used : CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) VolumeInfo(org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo) SnapshotDetailsVO(com.cloud.storage.dao.SnapshotDetailsVO)

Example 22 with SnapshotDetailsVO

use of com.cloud.storage.dao.SnapshotDetailsVO in project cloudstack by apache.

the class StorageSystemDataMotionStrategy method createVolumeFromSnapshot.

/**
     * If the underlying storage system is making use of read-only snapshots, this gives the storage system the opportunity to
     * create a volume from the snapshot so that we can copy the VHD file that should be inside of the snapshot to secondary storage.
     *
     * The resultant volume must be writable because we need to resign the SR and the VDI that should be inside of it before we copy
     * the VHD file to secondary storage.
     *
     * If the storage system is using writable snapshots, then nothing need be done by that storage system here because we can just
     * resign the SR and the VDI that should be inside of the snapshot before copying the VHD file to secondary storage.
     */
private void createVolumeFromSnapshot(HostVO hostVO, SnapshotInfo snapshotInfo, boolean keepGrantedAccess) {
    SnapshotDetailsVO snapshotDetails = handleSnapshotDetails(snapshotInfo.getId(), "tempVolume", "create");
    try {
        snapshotInfo.getDataStore().getDriver().createAsync(snapshotInfo.getDataStore(), snapshotInfo, null);
    } finally {
        _snapshotDetailsDao.remove(snapshotDetails.getId());
    }
    CopyCmdAnswer copyCmdAnswer = performResignature(snapshotInfo, hostVO, keepGrantedAccess);
    if (copyCmdAnswer == null || !copyCmdAnswer.getResult()) {
        if (copyCmdAnswer != null && !StringUtils.isEmpty(copyCmdAnswer.getDetails())) {
            throw new CloudRuntimeException(copyCmdAnswer.getDetails());
        } else {
            throw new CloudRuntimeException("Unable to create volume from snapshot");
        }
    }
}
Also used : CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) SnapshotDetailsVO(com.cloud.storage.dao.SnapshotDetailsVO) CopyCmdAnswer(org.apache.cloudstack.storage.command.CopyCmdAnswer)

Example 23 with SnapshotDetailsVO

use of com.cloud.storage.dao.SnapshotDetailsVO in project cloudstack by apache.

the class StorageSystemSnapshotStrategy method performSnapshotAndCopyOnHostSide.

private void performSnapshotAndCopyOnHostSide(VolumeInfo volumeInfo, SnapshotInfo snapshotInfo) {
    Map<String, String> sourceDetails = null;
    VolumeVO volumeVO = volumeDao.findById(volumeInfo.getId());
    Long vmInstanceId = volumeVO.getInstanceId();
    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);
    }
    HostVO hostVO = null;
    if (hostId != null) {
        hostVO = hostDao.findById(hostId);
    }
    if (hostVO == null || !ResourceState.Enabled.equals(hostVO.getResourceState())) {
        Optional<HostVO> optHostVO = getHost(volumeInfo.getDataCenterId(), false);
        if (optHostVO.isPresent()) {
            hostVO = optHostVO.get();
        }
    }
    if (hostVO == null) {
        final String errMsg = "Unable to locate an applicable host";
        s_logger.error("performSnapshotAndCopyOnHostSide: " + errMsg);
        throw new CloudRuntimeException(errMsg);
    }
    long storagePoolId = volumeVO.getPoolId();
    StoragePoolVO storagePoolVO = storagePoolDao.findById(storagePoolId);
    DataStore dataStore = dataStoreMgr.getDataStore(storagePoolId, DataStoreRole.Primary);
    Map<String, String> destDetails = getDestDetails(storagePoolVO, snapshotInfo);
    SnapshotAndCopyCommand snapshotAndCopyCommand = new SnapshotAndCopyCommand(volumeInfo.getPath(), sourceDetails, destDetails);
    SnapshotAndCopyAnswer snapshotAndCopyAnswer;
    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 (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 (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
    String path = snapshotAndCopyAnswer.getPath();
    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) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) VolumeVO(com.cloud.storage.VolumeVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) SnapshotAndCopyAnswer(org.apache.cloudstack.storage.command.SnapshotAndCopyAnswer) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) SnapshotAndCopyCommand(org.apache.cloudstack.storage.command.SnapshotAndCopyCommand)

Example 24 with SnapshotDetailsVO

use of com.cloud.storage.dao.SnapshotDetailsVO in project cloudstack by apache.

the class DateraPrimaryDataStoreDriver method revertSnapshot.

/**
 * Revert snapshot for a volume
 * @param snapshotInfo           Information about volume snapshot
 * @param snapshotOnPrimaryStore Not used
 * @throws CloudRuntimeException
 */
@Override
public void revertSnapshot(SnapshotInfo snapshotInfo, SnapshotInfo snapshotOnPrimaryStore, AsyncCompletionCallback<CommandResult> callback) {
    VolumeInfo volumeInfo = snapshotInfo.getBaseVolume();
    VolumeVO volumeVO = _volumeDao.findById(volumeInfo.getId());
    long storagePoolId = volumeVO.getPoolId();
    long csSnapshotId = snapshotInfo.getId();
    s_logger.info("Datera - restoreVolumeSnapshot from snapshotId " + String.valueOf(csSnapshotId) + " to volume" + volumeVO.getName());
    DateraObject.AppInstance appInstance;
    try {
        if (volumeVO == null || volumeVO.getRemoved() != null) {
            String errMsg = "The volume that the snapshot belongs to no longer exists.";
            CommandResult commandResult = new CommandResult();
            commandResult.setResult(errMsg);
            callback.complete(commandResult);
            return;
        }
        DateraObject.DateraConnection conn = DateraUtil.getDateraConnection(storagePoolId, _storagePoolDetailsDao);
        SnapshotDetailsVO snapshotDetails = snapshotDetailsDao.findDetail(csSnapshotId, DateraUtil.SNAPSHOT_ID);
        if (snapshotDetails != null && snapshotDetails.getValue() != null) {
            // Native snapshot being used, restore snapshot from Datera AppInstance
            String snapshotName = snapshotDetails.getValue();
            s_logger.info("Datera - restoreVolumeSnapshot: " + snapshotName);
            appInstance = DateraUtil.restoreVolumeSnapshot(conn, snapshotName);
            Preconditions.checkNotNull(appInstance);
            updateVolumeDetails(volumeInfo.getId(), appInstance.getSize());
        }
        CommandResult commandResult = new CommandResult();
        callback.complete(commandResult);
    } catch (Exception ex) {
        s_logger.debug("Error in 'revertSnapshot()'. CloudStack snapshot ID: " + csSnapshotId, ex);
        throw new CloudRuntimeException(ex.getMessage());
    }
}
Also used : VolumeVO(com.cloud.storage.VolumeVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) VolumeInfo(org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo) DateraObject(org.apache.cloudstack.storage.datastore.util.DateraObject) SnapshotDetailsVO(com.cloud.storage.dao.SnapshotDetailsVO) UnsupportedEncodingException(java.io.UnsupportedEncodingException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) CommandResult(org.apache.cloudstack.storage.command.CommandResult) CopyCommandResult(org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult)

Example 25 with SnapshotDetailsVO

use of com.cloud.storage.dao.SnapshotDetailsVO in project cloudstack by apache.

the class LinstorPrimaryDataStoreDriverImpl method handleSnapshotDetails.

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)

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