Search in sources :

Example 6 with VolumeDetailVO

use of com.cloud.storage.VolumeDetailVO in project cloudstack by apache.

the class StorageSystemDataMotionStrategy method handleCreateVolumeFromSnapshotBothOnStorageSystem.

private void handleCreateVolumeFromSnapshotBothOnStorageSystem(SnapshotInfo snapshotInfo, VolumeInfo volumeInfo, AsyncCompletionCallback<CopyCommandResult> callback) {
    CopyCmdAnswer copyCmdAnswer = null;
    String errMsg = null;
    try {
        HostVO hostVO = getHost(snapshotInfo);
        boolean usingBackendSnapshot = usingBackendSnapshotFor(snapshotInfo);
        boolean computeClusterSupportsResign = clusterDao.getSupportsResigning(hostVO.getClusterId());
        if (usingBackendSnapshot && !computeClusterSupportsResign) {
            String noSupportForResignErrMsg = "Unable to locate an applicable host with which to perform a resignature operation : Cluster ID = " + hostVO.getClusterId();
            LOGGER.warn(noSupportForResignErrMsg);
            throw new CloudRuntimeException(noSupportForResignErrMsg);
        }
        boolean canStorageSystemCreateVolumeFromVolume = canStorageSystemCreateVolumeFromVolume(snapshotInfo);
        boolean useCloning = usingBackendSnapshot || (canStorageSystemCreateVolumeFromVolume && computeClusterSupportsResign);
        VolumeDetailVO volumeDetail = null;
        if (useCloning) {
            volumeDetail = new VolumeDetailVO(volumeInfo.getId(), "cloneOfSnapshot", String.valueOf(snapshotInfo.getId()), false);
            volumeDetail = volumeDetailsDao.persist(volumeDetail);
        }
        // at this point, the snapshotInfo and volumeInfo should have the same disk offering ID (so either one should be OK to get a DiskOfferingVO instance)
        DiskOfferingVO diskOffering = _diskOfferingDao.findByIdIncludingRemoved(volumeInfo.getDiskOfferingId());
        SnapshotVO snapshot = _snapshotDao.findById(snapshotInfo.getId());
        // update the volume's hv_ss_reserve (hypervisor snapshot reserve) from a disk offering (used for managed storage)
        _volumeService.updateHypervisorSnapshotReserveForVolume(diskOffering, volumeInfo.getId(), snapshot.getHypervisorType());
        AsyncCallFuture<VolumeApiResult> future = _volumeService.createVolumeAsync(volumeInfo, volumeInfo.getDataStore());
        VolumeApiResult result = future.get();
        if (volumeDetail != null) {
            volumeDetailsDao.remove(volumeDetail.getId());
        }
        if (result.isFailed()) {
            LOGGER.warn("Failed to create a volume: " + result.getResult());
            throw new CloudRuntimeException(result.getResult());
        }
        volumeInfo = _volumeDataFactory.getVolume(volumeInfo.getId(), volumeInfo.getDataStore());
        volumeInfo.processEvent(Event.MigrationRequested);
        volumeInfo = _volumeDataFactory.getVolume(volumeInfo.getId(), volumeInfo.getDataStore());
        if (useCloning) {
            copyCmdAnswer = performResignature(volumeInfo, hostVO);
        } else {
            // asking for a XenServer host here so we don't always prefer to use XenServer hosts that support resigning
            // even when we don't need those hosts to do this kind of copy work
            hostVO = getHost(snapshotInfo.getDataCenterId(), false);
            copyCmdAnswer = performCopyOfVdi(volumeInfo, snapshotInfo, hostVO);
        }
        if (copyCmdAnswer == null || !copyCmdAnswer.getResult()) {
            if (copyCmdAnswer != null && !StringUtils.isEmpty(copyCmdAnswer.getDetails())) {
                errMsg = copyCmdAnswer.getDetails();
            } else {
                errMsg = "Unable to create volume from snapshot";
            }
        }
    } catch (Exception ex) {
        errMsg = ex.getMessage() != null ? ex.getMessage() : "Copy operation failed in 'StorageSystemDataMotionStrategy.handleCreateVolumeFromSnapshotBothOnStorageSystem'";
    }
    CopyCommandResult result = new CopyCommandResult(null, copyCmdAnswer);
    result.setResult(errMsg);
    callback.complete(result);
}
Also used : SnapshotVO(com.cloud.storage.SnapshotVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) DiskOfferingVO(com.cloud.storage.DiskOfferingVO) VolumeDetailVO(com.cloud.storage.VolumeDetailVO) VolumeApiResult(org.apache.cloudstack.engine.subsystem.api.storage.VolumeService.VolumeApiResult) CopyCommandResult(org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult) CopyCmdAnswer(org.apache.cloudstack.storage.command.CopyCmdAnswer) HostVO(com.cloud.host.HostVO) TimeoutException(java.util.concurrent.TimeoutException) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) OperationTimedoutException(com.cloud.exception.OperationTimedoutException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ExecutionException(java.util.concurrent.ExecutionException)

Example 7 with VolumeDetailVO

use of com.cloud.storage.VolumeDetailVO in project cloudstack by apache.

the class StorageSystemDataMotionStrategy method handleCreateVolumeFromTemplateBothOnStorageSystem.

/**
     * Clones a template present on the storage to a new volume and resignatures it.
     *
     * @param templateInfo   source template
     * @param volumeInfo  destination ROOT volume
     * @param callback  for async
     */
private void handleCreateVolumeFromTemplateBothOnStorageSystem(TemplateInfo templateInfo, VolumeInfo volumeInfo, AsyncCompletionCallback<CopyCommandResult> callback) {
    Preconditions.checkArgument(templateInfo != null, "Passing 'null' to templateInfo of handleCreateVolumeFromTemplateBothOnStorageSystem is not supported.");
    Preconditions.checkArgument(volumeInfo != null, "Passing 'null' to volumeInfo of handleCreateVolumeFromTemplateBothOnStorageSystem is not supported.");
    CopyCmdAnswer copyCmdAnswer = null;
    String errMsg = null;
    HostVO hostVO = getHost(volumeInfo.getDataCenterId(), true);
    if (hostVO == null) {
        throw new CloudRuntimeException("Unable to locate a host capable of resigning in the zone with the following ID: " + volumeInfo.getDataCenterId());
    }
    boolean computeClusterSupportsResign = clusterDao.getSupportsResigning(hostVO.getClusterId());
    if (!computeClusterSupportsResign) {
        String noSupportForResignErrMsg = "Unable to locate an applicable host with which to perform a resignature operation : Cluster ID = " + hostVO.getClusterId();
        LOGGER.warn(noSupportForResignErrMsg);
        throw new CloudRuntimeException(noSupportForResignErrMsg);
    }
    try {
        VolumeDetailVO volumeDetail = new VolumeDetailVO(volumeInfo.getId(), "cloneOfTemplate", String.valueOf(templateInfo.getId()), false);
        volumeDetail = volumeDetailsDao.persist(volumeDetail);
        AsyncCallFuture<VolumeApiResult> future = _volumeService.createVolumeAsync(volumeInfo, volumeInfo.getDataStore());
        int storagePoolMaxWaitSeconds = NumbersUtil.parseInt(_configDao.getValue(Config.StoragePoolMaxWaitSeconds.key()), 3600);
        VolumeApiResult result = future.get(storagePoolMaxWaitSeconds, TimeUnit.SECONDS);
        if (volumeDetail != null) {
            volumeDetailsDao.remove(volumeDetail.getId());
        }
        if (result.isFailed()) {
            LOGGER.warn("Failed to create a volume: " + result.getResult());
            throw new CloudRuntimeException(result.getResult());
        }
        volumeInfo = _volumeDataFactory.getVolume(volumeInfo.getId(), volumeInfo.getDataStore());
        volumeInfo.processEvent(Event.MigrationRequested);
        volumeInfo = _volumeDataFactory.getVolume(volumeInfo.getId(), volumeInfo.getDataStore());
        copyCmdAnswer = performResignature(volumeInfo, hostVO);
        if (copyCmdAnswer == null || !copyCmdAnswer.getResult()) {
            if (copyCmdAnswer != null && !StringUtils.isEmpty(copyCmdAnswer.getDetails())) {
                throw new CloudRuntimeException(copyCmdAnswer.getDetails());
            } else {
                throw new CloudRuntimeException("Unable to create a volume from a template");
            }
        }
    } catch (InterruptedException | ExecutionException | TimeoutException ex) {
        volumeInfo.getDataStore().getDriver().deleteAsync(volumeInfo.getDataStore(), volumeInfo, null);
        throw new CloudRuntimeException("Create volume from template (ID = " + templateInfo.getId() + ") failed " + ex.getMessage());
    }
    CopyCommandResult result = new CopyCommandResult(null, copyCmdAnswer);
    result.setResult(errMsg);
    callback.complete(result);
}
Also used : VolumeDetailVO(com.cloud.storage.VolumeDetailVO) VolumeApiResult(org.apache.cloudstack.engine.subsystem.api.storage.VolumeService.VolumeApiResult) HostVO(com.cloud.host.HostVO) EndPoint(org.apache.cloudstack.engine.subsystem.api.storage.EndPoint) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ExecutionException(java.util.concurrent.ExecutionException) CopyCommandResult(org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult) CopyCmdAnswer(org.apache.cloudstack.storage.command.CopyCmdAnswer) TimeoutException(java.util.concurrent.TimeoutException)

Example 8 with VolumeDetailVO

use of com.cloud.storage.VolumeDetailVO in project cloudstack by apache.

the class SolidFirePrimaryDataStoreDriver method getUsedBytes.

private long getUsedBytes(StoragePool storagePool, long volumeIdToIgnore) {
    long usedSpace = 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(), SolidFireUtil.VOLUME_SIZE);
            if (volumeDetail != null && volumeDetail.getValue() != null) {
                long volumeSize = Long.parseLong(volumeDetail.getValue());
                usedSpace += volumeSize;
            } else {
                SolidFireUtil.SolidFireConnection sfConnection = SolidFireUtil.getSolidFireConnection(storagePool.getId(), storagePoolDetailsDao);
                try {
                    long lVolumeId = Long.parseLong(volume.getFolder());
                    SolidFireUtil.SolidFireVolume sfVolume = SolidFireUtil.getVolume(sfConnection, lVolumeId);
                    long volumeSize = sfVolume.getTotalSize();
                    // SolidFireUtil.VOLUME_SIZE was introduced in 4.5.
                    // To be backward compatible with releases prior to 4.5, call updateVolumeDetails here.
                    // That way if SolidFireUtil.VOLUME_SIZE wasn't put in the volume_details table when the
                    // volume was initially created, it can be placed in volume_details here.
                    updateVolumeDetails(volume.getId(), volumeSize);
                    usedSpace += volumeSize;
                } catch (NumberFormatException ex) {
                // can be ignored (the "folder" column didn't have a valid "long" in it (hasn't been placed there yet))
                }
            }
        }
    }
    List<SnapshotVO> lstSnapshots = snapshotDao.listAll();
    if (lstSnapshots != null) {
        for (SnapshotVO snapshot : lstSnapshots) {
            SnapshotDetailsVO snapshotDetails = snapshotDetailsDao.findDetail(snapshot.getId(), SolidFireUtil.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(), SolidFireUtil.VOLUME_SIZE);
                if (snapshotDetails != null && snapshotDetails.getValue() != null) {
                    long snapshotSize = Long.parseLong(snapshotDetails.getValue());
                    usedSpace += snapshotSize;
                }
            }
        }
    }
    List<VMTemplateStoragePoolVO> lstTemplatePoolRefs = tmpltPoolDao.listByPoolId(storagePool.getId());
    if (lstTemplatePoolRefs != null) {
        for (VMTemplateStoragePoolVO templatePoolRef : lstTemplatePoolRefs) {
            usedSpace += templatePoolRef.getTemplateSize();
        }
    }
    return usedSpace;
}
Also used : VolumeDetailVO(com.cloud.storage.VolumeDetailVO) SnapshotDetailsVO(com.cloud.storage.dao.SnapshotDetailsVO) VMTemplateStoragePoolVO(com.cloud.storage.VMTemplateStoragePoolVO) SnapshotVO(com.cloud.storage.SnapshotVO) VolumeVO(com.cloud.storage.VolumeVO) SolidFireUtil(org.apache.cloudstack.storage.datastore.util.SolidFireUtil)

Example 9 with VolumeDetailVO

use of com.cloud.storage.VolumeDetailVO in project cloudstack by apache.

the class SolidFirePrimaryDataStoreDriver method updateVolumeDetails.

private void updateVolumeDetails(long volumeId, long sfVolumeSize) {
    volumeDetailsDao.removeDetail(volumeId, SolidFireUtil.VOLUME_SIZE);
    VolumeDetailVO volumeDetailVo = new VolumeDetailVO(volumeId, SolidFireUtil.VOLUME_SIZE, String.valueOf(sfVolumeSize), false);
    volumeDetailsDao.persist(volumeDetailVo);
}
Also used : VolumeDetailVO(com.cloud.storage.VolumeDetailVO)

Example 10 with VolumeDetailVO

use of com.cloud.storage.VolumeDetailVO in project cloudstack by apache.

the class ElastistorPrimaryDataStoreDriver method updateVolumeDetails.

//this method will utilize the volume details table to add third party volume properties
public void updateVolumeDetails(VolumeVO volume, FileSystem esvolume) {
    VolumeDetailVO compression = new VolumeDetailVO(volume.getId(), "compression", esvolume.getCompression(), false);
    _volumeDetailsDao.persist(compression);
    VolumeDetailVO deduplication = new VolumeDetailVO(volume.getId(), "deduplication", esvolume.getDeduplication(), false);
    _volumeDetailsDao.persist(deduplication);
    VolumeDetailVO sync = new VolumeDetailVO(volume.getId(), "sync", esvolume.getSync(), false);
    _volumeDetailsDao.persist(sync);
    VolumeDetailVO graceallowed = new VolumeDetailVO(volume.getId(), "graceallowed", esvolume.getGraceallowed(), false);
    _volumeDetailsDao.persist(graceallowed);
}
Also used : VolumeDetailVO(com.cloud.storage.VolumeDetailVO)

Aggregations

VolumeDetailVO (com.cloud.storage.VolumeDetailVO)10 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)5 Answer (com.cloud.agent.api.Answer)3 MigrateWithStorageAnswer (com.cloud.agent.api.MigrateWithStorageAnswer)3 MigrateWithStorageCompleteAnswer (com.cloud.agent.api.MigrateWithStorageCompleteAnswer)3 MigrateWithStorageReceiveAnswer (com.cloud.agent.api.MigrateWithStorageReceiveAnswer)3 MigrateWithStorageSendAnswer (com.cloud.agent.api.MigrateWithStorageSendAnswer)3 VolumeVO (com.cloud.storage.VolumeVO)3 HashMap (java.util.HashMap)3 PrimaryDataStoreDriver (org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreDriver)3 DeleteStoragePoolCommand (com.cloud.agent.api.DeleteStoragePoolCommand)2 HostVO (com.cloud.host.HostVO)2 SnapshotVO (com.cloud.storage.SnapshotVO)2 ExecutionException (java.util.concurrent.ExecutionException)2 TimeoutException (java.util.concurrent.TimeoutException)2 CopyCommandResult (org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult)2 VolumeApiResult (org.apache.cloudstack.engine.subsystem.api.storage.VolumeService.VolumeApiResult)2 CopyCmdAnswer (org.apache.cloudstack.storage.command.CopyCmdAnswer)2 CreateStoragePoolCommand (com.cloud.agent.api.CreateStoragePoolCommand)1 AgentUnavailableException (com.cloud.exception.AgentUnavailableException)1