Search in sources :

Example 46 with VolumeInfo

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

the class VolumeServiceImpl method migrateVolumes.

@Override
public AsyncCallFuture<CommandResult> migrateVolumes(final Map<VolumeInfo, DataStore> volumeMap, final VirtualMachineTO vmTo, final Host srcHost, final Host destHost) {
    final AsyncCallFuture<CommandResult> future = new AsyncCallFuture<>();
    final CommandResult res = new CommandResult();
    try {
        // Check to make sure there are no snapshot operations on a volume
        // and
        // put it in the migrating state.
        final List<VolumeInfo> volumesMigrating = new ArrayList<>();
        for (final Map.Entry<VolumeInfo, DataStore> entry : volumeMap.entrySet()) {
            final VolumeInfo volume = entry.getKey();
            if (!snapshotMgr.canOperateOnVolume(volume)) {
                s_logger.debug("Snapshots are being created on a volume. Volumes cannot be migrated now.");
                res.setResult("Snapshots are being created on a volume. Volumes cannot be migrated now.");
                future.complete(res);
                // to be put back in ready state.
                for (final VolumeInfo volumeMigrating : volumesMigrating) {
                    volumeMigrating.processEvent(Event.OperationFailed);
                }
                return future;
            } else {
                volume.processEvent(Event.MigrationRequested);
                volumesMigrating.add(volume);
            }
        }
        final MigrateVmWithVolumesContext<CommandResult> context = new MigrateVmWithVolumesContext<>(null, future, volumeMap);
        final AsyncCallbackDispatcher<VolumeServiceImpl, CopyCommandResult> caller = AsyncCallbackDispatcher.create(this);
        caller.setCallback(caller.getTarget().migrateVmWithVolumesCallBack(null, null)).setContext(context);
        motionSrv.copyAsync(volumeMap, vmTo, srcHost, destHost, caller);
    } catch (final Exception e) {
        s_logger.debug("Failed to copy volume", e);
        res.setResult(e.toString());
        future.complete(res);
    }
    return future;
}
Also used : ArrayList(java.util.ArrayList) VolumeInfo(com.cloud.engine.subsystem.api.storage.VolumeInfo) 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) AsyncCallFuture(com.cloud.framework.async.AsyncCallFuture) DataStore(com.cloud.engine.subsystem.api.storage.DataStore) PrimaryDataStore(com.cloud.engine.subsystem.api.storage.PrimaryDataStore) Map(java.util.Map) HashMap(java.util.HashMap) CopyCommandResult(com.cloud.engine.subsystem.api.storage.CopyCommandResult)

Example 47 with VolumeInfo

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

the class CloudStackPrimaryDataStoreDriverImpl method createAsync.

@Override
public void createAsync(final DataStore dataStore, final DataObject data, final AsyncCompletionCallback<CreateCmdResult> callback) {
    String errMsg = null;
    Answer answer = null;
    final CreateCmdResult result = new CreateCmdResult(null, null);
    if (data.getType() == DataObjectType.VOLUME) {
        try {
            answer = createVolume((VolumeInfo) data);
            if ((answer == null) || (!answer.getResult())) {
                result.setSuccess(false);
                if (answer != null) {
                    result.setResult(answer.getDetails());
                }
            } else {
                result.setAnswer(answer);
            }
        } catch (final StorageUnavailableException e) {
            s_logger.debug("failed to create volume", e);
            errMsg = e.toString();
        } catch (final Exception e) {
            s_logger.debug("failed to create volume", e);
            errMsg = e.toString();
        }
    }
    if (errMsg != null) {
        result.setResult(errMsg);
    }
    callback.complete(result);
}
Also used : ResizeVolumeAnswer(com.cloud.agent.api.storage.ResizeVolumeAnswer) Answer(com.cloud.agent.api.Answer) CopyCmdAnswer(com.cloud.storage.command.CopyCmdAnswer) StorageUnavailableException(com.cloud.exception.StorageUnavailableException) VolumeInfo(com.cloud.engine.subsystem.api.storage.VolumeInfo) CreateCmdResult(com.cloud.engine.subsystem.api.storage.CreateCmdResult) StorageUnavailableException(com.cloud.exception.StorageUnavailableException)

Example 48 with VolumeInfo

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

the class VolumeApiServiceImplTest method testResourceLimitCheckForUploadedVolume.

// The resource limit check for primary storage should not be skipped for Volume in 'Uploaded' state.
@Test
public void testResourceLimitCheckForUploadedVolume() throws NoSuchFieldException, IllegalAccessException, ResourceAllocationException {
    doThrow(new ResourceAllocationException("primary storage resource limit check failed", Resource.ResourceType.primary_storage)).when(_svc._resourceLimitMgr).checkResourceLimit(any(AccountVO.class), any(Resource.ResourceType.class), any(Long.class));
    UserVmVO vm = Mockito.mock(UserVmVO.class);
    VolumeInfo volumeToAttach = Mockito.mock(VolumeInfo.class);
    when(volumeToAttach.getId()).thenReturn(9L);
    when(volumeToAttach.getDataCenterId()).thenReturn(34L);
    when(volumeToAttach.getVolumeType()).thenReturn(Volume.Type.DATADISK);
    when(volumeToAttach.getInstanceId()).thenReturn(null);
    when(_userVmDao.findById(anyLong())).thenReturn(vm);
    when(vm.getType()).thenReturn(VirtualMachine.Type.User);
    when(vm.getState()).thenReturn(State.Running);
    when(vm.getDataCenterId()).thenReturn(34L);
    when(_svc._volsDao.findByInstanceAndType(anyLong(), any(Volume.Type.class))).thenReturn(new ArrayList(10));
    when(_svc.volFactory.getVolume(9L)).thenReturn(volumeToAttach);
    when(volumeToAttach.getState()).thenReturn(Volume.State.Uploaded);
    DataCenterVO zoneWithDisabledLocalStorage = Mockito.mock(DataCenterVO.class);
    when(_svc._dcDao.findById(anyLong())).thenReturn(zoneWithDisabledLocalStorage);
    when(zoneWithDisabledLocalStorage.isLocalStorageEnabled()).thenReturn(true);
    try {
        _svc.attachVolumeToVM(2L, 9L, null);
    } catch (InvalidParameterValueException e) {
        Assert.assertEquals(e.getMessage(), ("primary storage resource limit check failed"));
    }
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) UserVmVO(com.cloud.vm.UserVmVO) HypervisorType(com.cloud.hypervisor.Hypervisor.HypervisorType) AccessType(com.cloud.acl.SecurityChecker.AccessType) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) Matchers.anyLong(org.mockito.Matchers.anyLong) ArrayList(java.util.ArrayList) VolumeInfo(com.cloud.engine.subsystem.api.storage.VolumeInfo) ResourceAllocationException(com.cloud.exception.ResourceAllocationException) AccountVO(com.cloud.user.AccountVO) Test(org.junit.Test)

Example 49 with VolumeInfo

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

the class DataMotionServiceImpl method copyAsync.

@Override
public void copyAsync(final Map<VolumeInfo, DataStore> volumeMap, final VirtualMachineTO vmTo, final Host srcHost, final Host destHost, final AsyncCompletionCallback<CopyCommandResult> callback) {
    final DataMotionStrategy strategy = storageStrategyFactory.getDataMotionStrategy(volumeMap, srcHost, destHost);
    if (strategy == null) {
        final List<String> volumeIds = new LinkedList<>();
        for (final VolumeInfo volumeInfo : volumeMap.keySet()) {
            volumeIds.add(volumeInfo.getUuid());
        }
        throw new CloudRuntimeException("Can't find strategy to move data. " + "Source Host: " + srcHost.getName() + ", Destination Host: " + destHost.getName() + ", Volume UUIDs: " + StringUtils.join(volumeIds, ","));
    }
    strategy.copyAsync(volumeMap, vmTo, srcHost, destHost, callback);
}
Also used : CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) DataMotionStrategy(com.cloud.engine.subsystem.api.storage.DataMotionStrategy) VolumeInfo(com.cloud.engine.subsystem.api.storage.VolumeInfo) LinkedList(java.util.LinkedList)

Example 50 with VolumeInfo

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

the class AncientDataMotionStrategy method migrateVolumeToPool.

protected Answer migrateVolumeToPool(final DataObject srcData, final DataObject destData) {
    final String value = configDao.getValue(Config.MigrateWait.key());
    final int waitInterval = NumbersUtil.parseInt(value, Integer.parseInt(Config.MigrateWait.getDefaultValue()));
    final VolumeInfo volume = (VolumeInfo) srcData;
    final StoragePool destPool = (StoragePool) dataStoreMgr.getDataStore(destData.getDataStore().getId(), DataStoreRole.Primary);
    final MigrateVolumeCommand command = new MigrateVolumeCommand(volume.getId(), volume.getPath(), destPool, volume.getAttachedVmName(), volume.getVolumeType(), waitInterval);
    final EndPoint ep = selector.select(srcData, StorageAction.MIGRATEVOLUME);
    Answer answer = null;
    if (ep == null) {
        final String errMsg = "No remote endpoint to send command, check if host or ssvm is down?";
        s_logger.error(errMsg);
        answer = new Answer(command, false, errMsg);
    } else {
        answer = ep.sendMessage(command);
    }
    if (answer == null || !answer.getResult()) {
        throw new CloudRuntimeException("Failed to migrate volume " + volume + " to storage pool " + destPool);
    } else {
        // Update the volume details after migration.
        final VolumeVO volumeVo = volDao.findById(volume.getId());
        final Long oldPoolId = volume.getPoolId();
        volumeVo.setPath(((MigrateVolumeAnswer) answer).getVolumePath());
        final String chainInfo = ((MigrateVolumeAnswer) answer).getVolumeChainInfo();
        if (chainInfo != null) {
            volumeVo.setChainInfo(chainInfo);
        }
        volumeVo.setPodId(destPool.getPodId());
        volumeVo.setPoolId(destPool.getId());
        volumeVo.setLastPoolId(oldPoolId);
        // For SMB, pool credentials are also stored in the uri query string.  We trim the query string
        // part  here to make sure the credentials do not get stored in the db unencrypted.
        String folder = destPool.getPath();
        if (destPool.getPoolType() == StoragePoolType.SMB && folder != null && folder.contains("?")) {
            folder = folder.substring(0, folder.indexOf("?"));
        }
        volumeVo.setFolder(folder);
        volDao.update(volume.getId(), volumeVo);
    }
    return answer;
}
Also used : MigrateVolumeCommand(com.cloud.agent.api.storage.MigrateVolumeCommand) MigrateVolumeAnswer(com.cloud.agent.api.storage.MigrateVolumeAnswer) Answer(com.cloud.agent.api.Answer) StoragePool(com.cloud.storage.StoragePool) VolumeVO(com.cloud.storage.VolumeVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) MigrateVolumeAnswer(com.cloud.agent.api.storage.MigrateVolumeAnswer) VolumeInfo(com.cloud.engine.subsystem.api.storage.VolumeInfo) RemoteHostEndPoint(com.cloud.storage.RemoteHostEndPoint) EndPoint(com.cloud.engine.subsystem.api.storage.EndPoint) RemoteHostEndPoint(com.cloud.storage.RemoteHostEndPoint) EndPoint(com.cloud.engine.subsystem.api.storage.EndPoint)

Aggregations

VolumeInfo (com.cloud.engine.subsystem.api.storage.VolumeInfo)63 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)39 ExecutionException (java.util.concurrent.ExecutionException)26 ResourceAllocationException (com.cloud.exception.ResourceAllocationException)21 DataStore (com.cloud.engine.subsystem.api.storage.DataStore)19 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)19 InvalidParameterValueException (com.cloud.utils.exception.InvalidParameterValueException)17 VolumeVO (com.cloud.storage.VolumeVO)14 CopyCommandResult (com.cloud.engine.subsystem.api.storage.CopyCommandResult)12 StorageUnavailableException (com.cloud.exception.StorageUnavailableException)12 DB (com.cloud.utils.db.DB)12 StoragePoolVO (com.cloud.storage.datastore.db.StoragePoolVO)9 Account (com.cloud.user.Account)9 ArrayList (java.util.ArrayList)9 PrimaryDataStore (com.cloud.engine.subsystem.api.storage.PrimaryDataStore)8 SnapshotInfo (com.cloud.engine.subsystem.api.storage.SnapshotInfo)8 ActionEvent (com.cloud.event.ActionEvent)8 VolumeDataStoreVO (com.cloud.storage.datastore.db.VolumeDataStoreVO)8 AsyncCallFuture (com.cloud.framework.async.AsyncCallFuture)7 StoragePool (com.cloud.storage.StoragePool)7