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;
}
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);
}
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"));
}
}
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);
}
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;
}
Aggregations