Search in sources :

Example 31 with DataStore

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

the class VolumeDataFactoryImpl method getVolume.

@Override
public VolumeInfo getVolume(final long volumeId, final DataStoreRole storeRole) {
    final VolumeVO volumeVO = volumeDao.findById(volumeId);
    VolumeObject vol = null;
    if (storeRole == DataStoreRole.Image) {
        final VolumeDataStoreVO volumeStore = volumeStoreDao.findByVolume(volumeId);
        if (volumeStore != null) {
            final DataStore store = storeMgr.getDataStore(volumeStore.getDataStoreId(), DataStoreRole.Image);
            vol = VolumeObject.getVolumeObject(store, volumeVO);
        }
    } else {
        // Primary data store
        if (volumeVO.getPoolId() != null) {
            final DataStore store = storeMgr.getDataStore(volumeVO.getPoolId(), DataStoreRole.Primary);
            vol = VolumeObject.getVolumeObject(store, volumeVO);
        }
    }
    return vol;
}
Also used : VolumeVO(com.cloud.storage.VolumeVO) DataStore(com.cloud.engine.subsystem.api.storage.DataStore) VolumeDataStoreVO(com.cloud.storage.datastore.db.VolumeDataStoreVO)

Example 32 with DataStore

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

the class VolumeServiceImpl method migrateVmWithVolumesCallBack.

protected Void migrateVmWithVolumesCallBack(final AsyncCallbackDispatcher<VolumeServiceImpl, CopyCommandResult> callback, final MigrateVmWithVolumesContext<CommandResult> context) {
    final Map<VolumeInfo, DataStore> volumeToPool = context.volumeToPool;
    final CopyCommandResult result = callback.getResult();
    final AsyncCallFuture<CommandResult> future = context.future;
    final CommandResult res = new CommandResult();
    try {
        if (result.isFailed()) {
            res.setResult(result.getResult());
            for (final Map.Entry<VolumeInfo, DataStore> entry : volumeToPool.entrySet()) {
                final VolumeInfo volume = entry.getKey();
                volume.processEvent(Event.OperationFailed);
            }
            future.complete(res);
        } else {
            for (final Map.Entry<VolumeInfo, DataStore> entry : volumeToPool.entrySet()) {
                final VolumeInfo volume = entry.getKey();
                volume.processEvent(Event.OperationSuccessed);
            }
            future.complete(res);
        }
    } catch (final Exception e) {
        s_logger.error("Failed to process copy volume callback", e);
        res.setResult(e.toString());
        future.complete(res);
    }
    return null;
}
Also used : DataStore(com.cloud.engine.subsystem.api.storage.DataStore) PrimaryDataStore(com.cloud.engine.subsystem.api.storage.PrimaryDataStore) VolumeInfo(com.cloud.engine.subsystem.api.storage.VolumeInfo) CopyCommandResult(com.cloud.engine.subsystem.api.storage.CopyCommandResult) Map(java.util.Map) HashMap(java.util.HashMap) ResourceAllocationException(com.cloud.exception.ResourceAllocationException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ExecutionException(java.util.concurrent.ExecutionException) CommandResult(com.cloud.storage.command.CommandResult) CopyCommandResult(com.cloud.engine.subsystem.api.storage.CopyCommandResult)

Example 33 with DataStore

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

the class VolumeServiceImpl method registerVolumeCallback.

protected Void registerVolumeCallback(final AsyncCallbackDispatcher<VolumeServiceImpl, CreateCmdResult> callback, final CreateVolumeContext<VolumeApiResult> context) {
    final CreateCmdResult result = callback.getResult();
    final VolumeObject vo = (VolumeObject) context.volume;
    try {
        if (result.isFailed()) {
            vo.processEvent(Event.OperationFailed);
            // delete the volume entry from volumes table in case of failure
            final VolumeVO vol = volDao.findById(vo.getId());
            if (vol != null) {
                volDao.remove(vo.getId());
            }
        } else {
            vo.processEvent(Event.OperationSuccessed, result.getAnswer());
            if (vo.getSize() != null) {
                // publish usage events
                // get physical size from volume_store_ref table
                final DataStore ds = vo.getDataStore();
                final VolumeDataStoreVO volStore = _volumeStoreDao.findByStoreVolume(ds.getId(), vo.getId());
                if (volStore == null) {
                    s_logger.warn("No entry found in volume_store_ref for volume id: " + vo.getId() + " and image store id: " + ds.getId() + " at the end of uploading volume!");
                }
                final Scope dsScope = ds.getScope();
                if (dsScope.getScopeType() == ScopeType.REGION) {
                    _resourceLimitMgr.incrementResourceCount(vo.getAccountId(), ResourceType.secondary_storage, vo.getSize());
                }
            }
        }
        final VolumeApiResult res = new VolumeApiResult(vo);
        context.future.complete(res);
        return null;
    } catch (final Exception e) {
        s_logger.error("register volume failed: ", e);
        // delete the volume entry from volumes table in case of failure
        final VolumeVO vol = volDao.findById(vo.getId());
        if (vol != null) {
            volDao.remove(vo.getId());
        }
        final VolumeApiResult res = new VolumeApiResult(null);
        context.future.complete(res);
        return null;
    }
}
Also used : VolumeVO(com.cloud.storage.VolumeVO) Scope(com.cloud.engine.subsystem.api.storage.Scope) DataStore(com.cloud.engine.subsystem.api.storage.DataStore) PrimaryDataStore(com.cloud.engine.subsystem.api.storage.PrimaryDataStore) VolumeDataStoreVO(com.cloud.storage.datastore.db.VolumeDataStoreVO) CreateCmdResult(com.cloud.engine.subsystem.api.storage.CreateCmdResult) ResourceAllocationException(com.cloud.exception.ResourceAllocationException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ExecutionException(java.util.concurrent.ExecutionException)

Example 34 with DataStore

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

the class StorageSystemSnapshotStrategy method canHandle.

@Override
public StrategyPriority canHandle(final Snapshot snapshot, final SnapshotOperation op) {
    if (SnapshotOperation.REVERT.equals(op)) {
        return StrategyPriority.CANT_HANDLE;
    }
    final long volumeId = snapshot.getVolumeId();
    final VolumeVO volumeVO = _volumeDao.findByIdIncludingRemoved(volumeId);
    final long storagePoolId = volumeVO.getPoolId();
    final DataStore dataStore = _dataStoreMgr.getDataStore(storagePoolId, DataStoreRole.Primary);
    if (dataStore != null) {
        final Map<String, String> mapCapabilities = dataStore.getDriver().getCapabilities();
        if (mapCapabilities != null) {
            final String value = mapCapabilities.get(DataStoreCapabilities.STORAGE_SYSTEM_SNAPSHOT.toString());
            final Boolean supportsStorageSystemSnapshots = new Boolean(value);
            if (supportsStorageSystemSnapshots) {
                return StrategyPriority.HIGHEST;
            }
        }
    }
    return StrategyPriority.CANT_HANDLE;
}
Also used : VolumeVO(com.cloud.storage.VolumeVO) DataStore(com.cloud.engine.subsystem.api.storage.DataStore)

Example 35 with DataStore

use of com.cloud.engine.subsystem.api.storage.DataStore 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)

Aggregations

DataStore (com.cloud.engine.subsystem.api.storage.DataStore)96 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)43 InvalidParameterValueException (com.cloud.utils.exception.InvalidParameterValueException)23 ExecutionException (java.util.concurrent.ExecutionException)23 VolumeInfo (com.cloud.engine.subsystem.api.storage.VolumeInfo)19 ZoneScope (com.cloud.engine.subsystem.api.storage.ZoneScope)17 TemplateDataStoreVO (com.cloud.storage.datastore.db.TemplateDataStoreVO)17 ArrayList (java.util.ArrayList)17 VolumeVO (com.cloud.storage.VolumeVO)16 StorageUnavailableException (com.cloud.exception.StorageUnavailableException)15 EndPoint (com.cloud.engine.subsystem.api.storage.EndPoint)14 PrimaryDataStore (com.cloud.engine.subsystem.api.storage.PrimaryDataStore)14 DB (com.cloud.utils.db.DB)14 PermissionDeniedException (com.cloud.exception.PermissionDeniedException)12 SnapshotDataStoreVO (com.cloud.storage.datastore.db.SnapshotDataStoreVO)12 StoragePoolVO (com.cloud.storage.datastore.db.StoragePoolVO)12 VolumeDataStoreVO (com.cloud.storage.datastore.db.VolumeDataStoreVO)12 ConfigurationException (javax.naming.ConfigurationException)12 Answer (com.cloud.agent.api.Answer)10 VMTemplateVO (com.cloud.storage.VMTemplateVO)10