Search in sources :

Example 1 with VolumeApiResult

use of com.cloud.engine.subsystem.api.storage.VolumeService.VolumeApiResult in project cosmic by MissionCriticalCloud.

the class VolumeApiServiceImpl method liveMigrateVolume.

@DB
protected Volume liveMigrateVolume(final Volume volume, final StoragePool destPool) throws StorageUnavailableException {
    final VolumeInfo vol = volFactory.getVolume(volume.getId(), true);
    final AsyncCallFuture<VolumeApiResult> future = volService.migrateVolume(vol, (DataStore) destPool);
    try {
        final VolumeApiResult result = future.get();
        if (result.isFailed()) {
            s_logger.debug("Live migrate volume failed:" + result.getResult());
            throw new StorageUnavailableException("Live migrate volume failed: " + result.getResult(), destPool.getId());
        }
        return result.getVolume();
    } catch (final InterruptedException e) {
        s_logger.debug("Live migrate volume failed", e);
        throw new CloudRuntimeException(e.getMessage());
    } catch (final ExecutionException e) {
        s_logger.debug("Live migrate volume failed", e);
        throw new CloudRuntimeException(e.getMessage());
    }
}
Also used : StorageUnavailableException(com.cloud.exception.StorageUnavailableException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) VolumeInfo(com.cloud.engine.subsystem.api.storage.VolumeInfo) VolumeApiResult(com.cloud.engine.subsystem.api.storage.VolumeService.VolumeApiResult) ExecutionException(java.util.concurrent.ExecutionException) DB(com.cloud.utils.db.DB)

Example 2 with VolumeApiResult

use of com.cloud.engine.subsystem.api.storage.VolumeService.VolumeApiResult in project cosmic by MissionCriticalCloud.

the class VolumeApiServiceImpl method deleteVolume.

@Override
@DB
@ActionEvent(eventType = EventTypes.EVENT_VOLUME_DELETE, eventDescription = "deleting volume")
public boolean deleteVolume(final long volumeId, final Account caller) throws ConcurrentOperationException {
    final VolumeVO volume = _volsDao.findById(volumeId);
    if (volume == null) {
        throw new InvalidParameterValueException("Unable to find volume with ID: " + volumeId);
    }
    if (!_snapshotMgr.canOperateOnVolume(volume)) {
        throw new InvalidParameterValueException("There are snapshot operations in progress on the volume, unable to delete it");
    }
    _accountMgr.checkAccess(caller, null, true, volume);
    if (volume.getInstanceId() != null) {
        throw new InvalidParameterValueException("Please specify a volume that is not attached to any VM.");
    }
    if (volume.getState() == Volume.State.UploadOp) {
        final VolumeDataStoreVO volumeStore = _volumeStoreDao.findByVolume(volume.getId());
        if (volumeStore.getDownloadState() == VMTemplateStorageResourceAssoc.Status.DOWNLOAD_IN_PROGRESS) {
            throw new InvalidParameterValueException("Please specify a volume that is not uploading");
        }
    }
    if (volume.getState() == Volume.State.NotUploaded || volume.getState() == Volume.State.UploadInProgress) {
        throw new InvalidParameterValueException("The volume is either getting uploaded or it may be initiated shortly, please wait for it to be completed");
    }
    try {
        if (volume.getState() != Volume.State.Destroy && volume.getState() != Volume.State.Expunging && volume.getState() != Volume.State.Expunged) {
            final Long instanceId = volume.getInstanceId();
            if (!volService.destroyVolume(volume.getId())) {
                return false;
            }
            final VMInstanceVO vmInstance = _vmInstanceDao.findById(instanceId);
            if (instanceId == null || vmInstance.getType().equals(VirtualMachine.Type.User)) {
                // Decrement the resource count for volumes and primary storage belonging user VM's only
                _resourceLimitMgr.decrementResourceCount(volume.getAccountId(), ResourceType.volume, volume.isDisplayVolume());
            }
        }
        // Mark volume as removed if volume has not been created on primary or secondary
        if (volume.getState() == Volume.State.Allocated) {
            _volsDao.remove(volumeId);
            stateTransitTo(volume, Volume.Event.DestroyRequested);
            return true;
        }
        // expunge volume from primary if volume is on primary
        final VolumeInfo volOnPrimary = volFactory.getVolume(volume.getId(), DataStoreRole.Primary);
        if (volOnPrimary != null) {
            s_logger.info("Expunging volume " + volume.getId() + " from primary data store");
            final AsyncCallFuture<VolumeApiResult> future = volService.expungeVolumeAsync(volOnPrimary);
            future.get();
            // decrement primary storage count
            _resourceLimitMgr.recalculateResourceCount(volume.getAccountId(), volume.getDomainId(), ResourceType.primary_storage.getOrdinal());
        }
        // expunge volume from secondary if volume is on image store
        final VolumeInfo volOnSecondary = volFactory.getVolume(volume.getId(), DataStoreRole.Image);
        if (volOnSecondary != null) {
            s_logger.info("Expunging volume " + volume.getId() + " from secondary data store");
            final AsyncCallFuture<VolumeApiResult> future2 = volService.expungeVolumeAsync(volOnSecondary);
            future2.get();
            // decrement secondary storage count
            _resourceLimitMgr.recalculateResourceCount(volume.getAccountId(), volume.getDomainId(), ResourceType.secondary_storage.getOrdinal());
        }
        // delete all cache entries for this volume
        final List<VolumeInfo> cacheVols = volFactory.listVolumeOnCache(volume.getId());
        for (final VolumeInfo volOnCache : cacheVols) {
            s_logger.info("Delete volume from image cache store: " + volOnCache.getDataStore().getName());
            volOnCache.delete();
        }
    } catch (InterruptedException | ExecutionException | NoTransitionException e) {
        s_logger.warn("Failed to expunge volume:", e);
        return false;
    }
    return true;
}
Also used : VMInstanceVO(com.cloud.vm.VMInstanceVO) VolumeInfo(com.cloud.engine.subsystem.api.storage.VolumeInfo) VolumeApiResult(com.cloud.engine.subsystem.api.storage.VolumeService.VolumeApiResult) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) VolumeDataStoreVO(com.cloud.storage.datastore.db.VolumeDataStoreVO) ExecutionException(java.util.concurrent.ExecutionException) ActionEvent(com.cloud.event.ActionEvent) DB(com.cloud.utils.db.DB)

Example 3 with VolumeApiResult

use of com.cloud.engine.subsystem.api.storage.VolumeService.VolumeApiResult in project cosmic by MissionCriticalCloud.

the class StorageSystemDataMotionStrategy method handleCreateVolumeFromSnapshotBothOnStorageSystem.

private Void handleCreateVolumeFromSnapshotBothOnStorageSystem(final SnapshotInfo snapshotInfo, VolumeInfo volumeInfo, final AsyncCompletionCallback<CopyCommandResult> callback) {
    try {
        // 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)
        final DiskOfferingVO diskOffering = _diskOfferingDao.findByIdIncludingRemoved(volumeInfo.getDiskOfferingId());
        final 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());
        final AsyncCallFuture<VolumeApiResult> future = _volumeService.createVolumeAsync(volumeInfo, volumeInfo.getDataStore());
        final VolumeApiResult result = future.get();
        if (result.isFailed()) {
            s_logger.debug("Failed to create a volume: " + result.getResult());
            throw new CloudRuntimeException(result.getResult());
        }
    } catch (final Exception ex) {
        throw new CloudRuntimeException(ex.getMessage());
    }
    volumeInfo = _volumeDataFactory.getVolume(volumeInfo.getId(), volumeInfo.getDataStore());
    volumeInfo.processEvent(Event.MigrationRequested);
    volumeInfo = _volumeDataFactory.getVolume(volumeInfo.getId(), volumeInfo.getDataStore());
    final HostVO hostVO = getHost(snapshotInfo.getDataStore().getId());
    final String value = _configDao.getValue(Config.PrimaryStorageDownloadWait.toString());
    final int primaryStorageDownloadWait = NumbersUtil.parseInt(value, Integer.parseInt(Config.PrimaryStorageDownloadWait.getDefaultValue()));
    final CopyCommand copyCommand = new CopyCommand(snapshotInfo.getTO(), volumeInfo.getTO(), primaryStorageDownloadWait, VirtualMachineManager.ExecuteInSequence.value());
    CopyCmdAnswer copyCmdAnswer = null;
    try {
        _volumeService.grantAccess(snapshotInfo, hostVO, snapshotInfo.getDataStore());
        _volumeService.grantAccess(volumeInfo, hostVO, volumeInfo.getDataStore());
        final Map<String, String> srcDetails = getSnapshotDetails(_storagePoolDao.findById(snapshotInfo.getDataStore().getId()), snapshotInfo);
        copyCommand.setOptions(srcDetails);
        final Map<String, String> destDetails = getVolumeDetails(volumeInfo);
        copyCommand.setOptions2(destDetails);
        copyCmdAnswer = (CopyCmdAnswer) _agentMgr.send(hostVO.getId(), copyCommand);
    } catch (final Exception ex) {
        throw new CloudRuntimeException(ex.getMessage());
    } finally {
        try {
            _volumeService.revokeAccess(snapshotInfo, hostVO, snapshotInfo.getDataStore());
        } catch (final Exception ex) {
            s_logger.debug(ex.getMessage(), ex);
        }
        try {
            _volumeService.revokeAccess(volumeInfo, hostVO, volumeInfo.getDataStore());
        } catch (final Exception ex) {
            s_logger.debug(ex.getMessage(), ex);
        }
    }
    String errMsg = null;
    if (copyCmdAnswer == null || !copyCmdAnswer.getResult()) {
        if (copyCmdAnswer != null && copyCmdAnswer.getDetails() != null && !copyCmdAnswer.getDetails().isEmpty()) {
            errMsg = copyCmdAnswer.getDetails();
        } else {
            errMsg = "Unable to perform host-side operation";
        }
    }
    final CopyCommandResult result = new CopyCommandResult(null, copyCmdAnswer);
    result.setResult(errMsg);
    callback.complete(result);
    return null;
}
Also used : CopyCommand(com.cloud.storage.command.CopyCommand) VolumeApiResult(com.cloud.engine.subsystem.api.storage.VolumeService.VolumeApiResult) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) HostVO(com.cloud.host.HostVO) SnapshotVO(com.cloud.storage.SnapshotVO) DiskOfferingVO(com.cloud.storage.DiskOfferingVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) CopyCommandResult(com.cloud.engine.subsystem.api.storage.CopyCommandResult) CopyCmdAnswer(com.cloud.storage.command.CopyCmdAnswer)

Example 4 with VolumeApiResult

use of com.cloud.engine.subsystem.api.storage.VolumeService.VolumeApiResult in project cosmic by MissionCriticalCloud.

the class VolumeApiServiceImpl method orchestrateExtractVolume.

private String orchestrateExtractVolume(final long volumeId, final long zoneId) {
    // get latest volume state to make sure that it is not updated by other parallel operations
    final VolumeVO volume = _volsDao.findById(volumeId);
    if (volume == null || volume.getState() != Volume.State.Ready) {
        throw new InvalidParameterValueException("Volume to be extracted has been removed or not in right state!");
    }
    // perform extraction
    final ImageStoreEntity secStore = (ImageStoreEntity) dataStoreMgr.getImageStore(zoneId);
    final String value = _configDao.getValue(Config.CopyVolumeWait.toString());
    NumbersUtil.parseInt(value, Integer.parseInt(Config.CopyVolumeWait.getDefaultValue()));
    // Copy volume from primary to secondary storage
    final VolumeInfo srcVol = volFactory.getVolume(volumeId);
    final AsyncCallFuture<VolumeApiResult> cvAnswer = volService.copyVolume(srcVol, secStore);
    // Check if you got a valid answer.
    final VolumeApiResult cvResult;
    try {
        cvResult = cvAnswer.get();
    } catch (final InterruptedException e1) {
        s_logger.debug("failed copy volume", e1);
        throw new CloudRuntimeException("Failed to copy volume", e1);
    } catch (final ExecutionException e1) {
        s_logger.debug("failed copy volume", e1);
        throw new CloudRuntimeException("Failed to copy volume", e1);
    }
    if (cvResult == null || cvResult.isFailed()) {
        final String errorString = "Failed to copy the volume from the source primary storage pool to secondary storage.";
        throw new CloudRuntimeException(errorString);
    }
    final VolumeInfo vol = cvResult.getVolume();
    final String extractUrl = secStore.createEntityExtractUrl(vol.getPath(), vol.getFormat(), vol);
    final VolumeDataStoreVO volumeStoreRef = _volumeStoreDao.findByVolume(volumeId);
    volumeStoreRef.setExtractUrl(extractUrl);
    volumeStoreRef.setExtractUrlCreated(DateUtil.now());
    _volumeStoreDao.update(volumeStoreRef.getId(), volumeStoreRef);
    return extractUrl;
}
Also used : InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) VolumeDataStoreVO(com.cloud.storage.datastore.db.VolumeDataStoreVO) ImageStoreEntity(com.cloud.storage.image.datastore.ImageStoreEntity) VolumeInfo(com.cloud.engine.subsystem.api.storage.VolumeInfo) VolumeApiResult(com.cloud.engine.subsystem.api.storage.VolumeService.VolumeApiResult) ExecutionException(java.util.concurrent.ExecutionException)

Example 5 with VolumeApiResult

use of com.cloud.engine.subsystem.api.storage.VolumeService.VolumeApiResult in project cosmic by MissionCriticalCloud.

the class VolumeApiServiceImpl method orchestrateResizeVolume.

private VolumeVO orchestrateResizeVolume(final long volumeId, final long currentSize, final long newSize, final Long newMinIops, final Long newMaxIops, final Long newDiskOfferingId, final boolean shrinkOk) {
    VolumeVO volume = _volsDao.findById(volumeId);
    final UserVmVO userVm = _userVmDao.findById(volume.getInstanceId());
    /*
         * get a list of hosts to send the commands to, try the system the
         * associated vm is running on first, then the last known place it ran.
         * If not attached to a userVm, we pass 'none' and resizevolume.sh is ok
         * with that since it only needs the vm name to live resize
         */
    long[] hosts = null;
    String instanceName = "none";
    if (userVm != null) {
        instanceName = userVm.getInstanceName();
        if (userVm.getHostId() != null) {
            hosts = new long[] { userVm.getHostId() };
        } else if (userVm.getLastHostId() != null) {
            hosts = new long[] { userVm.getLastHostId() };
        }
        final String errorMsg = "The VM must be stopped or the disk detached in order to resize with the XenServer Hypervisor.";
        final StoragePoolVO storagePool = _storagePoolDao.findById(volume.getPoolId());
        if (storagePool.isManaged() && storagePool.getHypervisor() == HypervisorType.Any && hosts != null && hosts.length > 0) {
            final HostVO host = _hostDao.findById(hosts[0]);
            if (currentSize != newSize && host.getHypervisorType() == HypervisorType.XenServer && !userVm.getState().equals(State.Stopped)) {
                throw new InvalidParameterValueException(errorMsg);
            }
        }
        /* Xen only works offline, SR does not support VDI.resizeOnline */
        if (currentSize != newSize && _volsDao.getHypervisorType(volume.getId()) == HypervisorType.XenServer && !userVm.getState().equals(State.Stopped)) {
            throw new InvalidParameterValueException(errorMsg);
        }
    }
    final ResizeVolumePayload payload = new ResizeVolumePayload(newSize, newMinIops, newMaxIops, shrinkOk, instanceName, hosts);
    try {
        final VolumeInfo vol = volFactory.getVolume(volume.getId());
        vol.addPayload(payload);
        final StoragePoolVO storagePool = _storagePoolDao.findById(vol.getPoolId());
        // needs to tell the hypervisor to resize the disk
        if (storagePool.isManaged() && currentSize != newSize) {
            if (hosts != null && hosts.length > 0) {
                volService.resizeVolumeOnHypervisor(volumeId, newSize, hosts[0], instanceName);
            }
            volume.setSize(newSize);
            _volsDao.update(volume.getId(), volume);
        }
        // this call to resize has a different impact depending on whether the
        // underlying primary storage is managed or not
        // if managed, this is the chance for the plug-in to change IOPS value, if applicable
        // if not managed, this is the chance for the plug-in to talk to the hypervisor layer
        // to change the size of the disk
        final AsyncCallFuture<VolumeApiResult> future = volService.resize(vol);
        final VolumeApiResult result = future.get();
        if (result.isFailed()) {
            s_logger.warn("Failed to resize the volume " + volume);
            String details = "";
            if (result.getResult() != null && !result.getResult().isEmpty()) {
                details = result.getResult();
            }
            throw new CloudRuntimeException(details);
        }
        volume = _volsDao.findById(volume.getId());
        if (newDiskOfferingId != null) {
            volume.setDiskOfferingId(newDiskOfferingId);
        }
        if (currentSize != newSize) {
            volume.setSize(newSize);
        }
        _volsDao.update(volume.getId(), volume);
        /* Update resource count for the account on primary storage resource */
        if (!shrinkOk) {
            _resourceLimitMgr.incrementResourceCount(volume.getAccountId(), ResourceType.primary_storage, volume.isDisplayVolume(), new Long(newSize - currentSize));
        } else {
            _resourceLimitMgr.decrementResourceCount(volume.getAccountId(), ResourceType.primary_storage, volume.isDisplayVolume(), new Long(currentSize - newSize));
        }
        return volume;
    } catch (final InterruptedException e) {
        s_logger.warn("failed get resize volume result", e);
        throw new CloudRuntimeException(e.getMessage());
    } catch (final ExecutionException e) {
        s_logger.warn("failed get resize volume result", e);
        throw new CloudRuntimeException(e.getMessage());
    } catch (final Exception e) {
        s_logger.warn("failed get resize volume result", e);
        throw new CloudRuntimeException(e.getMessage());
    }
}
Also used : UserVmVO(com.cloud.vm.UserVmVO) VolumeInfo(com.cloud.engine.subsystem.api.storage.VolumeInfo) VolumeApiResult(com.cloud.engine.subsystem.api.storage.VolumeService.VolumeApiResult) HostVO(com.cloud.host.HostVO) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) TransactionCallbackWithException(com.cloud.utils.db.TransactionCallbackWithException) CloudException(com.cloud.exception.CloudException) StorageUnavailableException(com.cloud.exception.StorageUnavailableException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ExecutionException(java.util.concurrent.ExecutionException) ResourceAllocationException(com.cloud.exception.ResourceAllocationException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) PermissionDeniedException(com.cloud.exception.PermissionDeniedException) MalformedURLException(java.net.MalformedURLException) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) StoragePoolVO(com.cloud.storage.datastore.db.StoragePoolVO) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

VolumeApiResult (com.cloud.engine.subsystem.api.storage.VolumeService.VolumeApiResult)7 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)6 ExecutionException (java.util.concurrent.ExecutionException)6 VolumeInfo (com.cloud.engine.subsystem.api.storage.VolumeInfo)5 InvalidParameterValueException (com.cloud.utils.exception.InvalidParameterValueException)5 StorageUnavailableException (com.cloud.exception.StorageUnavailableException)3 StoragePoolVO (com.cloud.storage.datastore.db.StoragePoolVO)3 VolumeDataStoreVO (com.cloud.storage.datastore.db.VolumeDataStoreVO)3 DB (com.cloud.utils.db.DB)3 DataStore (com.cloud.engine.subsystem.api.storage.DataStore)2 PermissionDeniedException (com.cloud.exception.PermissionDeniedException)2 HostVO (com.cloud.host.HostVO)2 ManagementServerHost (com.cloud.cluster.ManagementServerHost)1 CopyCommandResult (com.cloud.engine.subsystem.api.storage.CopyCommandResult)1 DataStoreLifeCycle (com.cloud.engine.subsystem.api.storage.DataStoreLifeCycle)1 DataStoreProvider (com.cloud.engine.subsystem.api.storage.DataStoreProvider)1 EndPoint (com.cloud.engine.subsystem.api.storage.EndPoint)1 PrimaryDataStoreLifeCycle (com.cloud.engine.subsystem.api.storage.PrimaryDataStoreLifeCycle)1 TemplateApiResult (com.cloud.engine.subsystem.api.storage.TemplateService.TemplateApiResult)1 ActionEvent (com.cloud.event.ActionEvent)1