use of org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo in project cloudstack by apache.
the class VmwareStorageMotionStrategyTest method testStrategyHandlesVmwareHosts.
@Test
public void testStrategyHandlesVmwareHosts() throws Exception {
Host srcHost = mock(Host.class);
Host destHost = mock(Host.class);
when(srcHost.getHypervisorType()).thenReturn(HypervisorType.VMware);
when(destHost.getHypervisorType()).thenReturn(HypervisorType.VMware);
Map<VolumeInfo, DataStore> volumeMap = new HashMap<VolumeInfo, DataStore>();
StrategyPriority canHandle = strategy.canHandle(volumeMap, srcHost, destHost);
assertTrue("The strategy is only supposed to handle vmware hosts", canHandle == StrategyPriority.HYPERVISOR);
}
use of org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo in project cloudstack by apache.
the class VmwareStorageMotionStrategy method migrateVmWithVolumesWithinCluster.
private Answer migrateVmWithVolumesWithinCluster(VMInstanceVO vm, VirtualMachineTO to, Host srcHost, Host destHost, Map<VolumeInfo, DataStore> volumeToPool) throws AgentUnavailableException {
// Initiate migration of a virtual machine with it's volumes.
try {
List<Pair<VolumeTO, StorageFilerTO>> volumeToFilerto = new ArrayList<Pair<VolumeTO, StorageFilerTO>>();
for (Map.Entry<VolumeInfo, DataStore> entry : volumeToPool.entrySet()) {
VolumeInfo volume = entry.getKey();
VolumeTO volumeTo = new VolumeTO(volume, storagePoolDao.findById(volume.getPoolId()));
StorageFilerTO filerTo = new StorageFilerTO((StoragePool) entry.getValue());
volumeToFilerto.add(new Pair<VolumeTO, StorageFilerTO>(volumeTo, filerTo));
}
MigrateWithStorageCommand command = new MigrateWithStorageCommand(to, volumeToFilerto, destHost.getGuid());
MigrateWithStorageAnswer answer = (MigrateWithStorageAnswer) agentMgr.send(srcHost.getId(), command);
if (answer == null) {
s_logger.error("Migration with storage of vm " + vm + " failed.");
throw new CloudRuntimeException("Error while migrating the vm " + vm + " to host " + destHost);
} else if (!answer.getResult()) {
s_logger.error("Migration with storage of vm " + vm + " failed. Details: " + answer.getDetails());
throw new CloudRuntimeException("Error while migrating the vm " + vm + " to host " + destHost + ". " + answer.getDetails());
} else {
// Update the volume details after migration.
updateVolumesAfterMigration(volumeToPool, answer.getVolumeTos());
}
return answer;
} catch (OperationTimedoutException e) {
s_logger.error("Error while migrating vm " + vm + " to host " + destHost, e);
throw new AgentUnavailableException("Operation timed out on storage motion for " + vm, destHost.getId());
}
}
use of org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo in project cloudstack by apache.
the class VmwareStorageMotionStrategyTest method testMigrateWithinClusterSuccess.
@Test
public void testMigrateWithinClusterSuccess() throws Exception {
Host srcHost = mock(Host.class);
Host destHost = mock(Host.class);
when(srcHost.getClusterId()).thenReturn(1L);
when(destHost.getClusterId()).thenReturn(1L);
Map<VolumeInfo, DataStore> volumeMap = new HashMap<VolumeInfo, DataStore>();
VirtualMachineTO to = mock(VirtualMachineTO.class);
when(to.getId()).thenReturn(6L);
VMInstanceVO instance = mock(VMInstanceVO.class);
when(instanceDao.findById(6L)).thenReturn(instance);
MockContext<CommandResult> context = new MockContext<CommandResult>(null, null, volumeMap);
AsyncCallbackDispatcher<VmwareStorageMotionStrategyTest, CopyCommandResult> caller = AsyncCallbackDispatcher.create(this);
caller.setCallback(caller.getTarget().mockCallBack(null, null)).setContext(context);
MigrateWithStorageAnswer migAnswerMock = mock(MigrateWithStorageAnswer.class);
when(migAnswerMock.getResult()).thenReturn(true);
when(agentMgr.send(anyLong(), isA(MigrateWithStorageCommand.class))).thenReturn(migAnswerMock);
strategy.copyAsync(volumeMap, to, srcHost, destHost, caller);
assertTrue("Migration within cluster isn't successful.", result.isSuccess());
}
use of org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo in project cloudstack by apache.
the class VmwareStorageMotionStrategyTest method testMigrateAcrossClusterSuccess.
@Test
public void testMigrateAcrossClusterSuccess() throws Exception {
Host srcHost = mock(Host.class);
Host destHost = mock(Host.class);
when(srcHost.getClusterId()).thenReturn(1L);
when(destHost.getClusterId()).thenReturn(2L);
Map<VolumeInfo, DataStore> volumeMap = new HashMap<VolumeInfo, DataStore>();
VirtualMachineTO to = mock(VirtualMachineTO.class);
when(to.getId()).thenReturn(6L);
VMInstanceVO instance = mock(VMInstanceVO.class);
when(instanceDao.findById(6L)).thenReturn(instance);
MockContext<CommandResult> context = new MockContext<CommandResult>(null, null, volumeMap);
AsyncCallbackDispatcher<VmwareStorageMotionStrategyTest, CopyCommandResult> caller = AsyncCallbackDispatcher.create(this);
caller.setCallback(caller.getTarget().mockCallBack(null, null)).setContext(context);
MigrateWithStorageAnswer migAnswerMock = mock(MigrateWithStorageAnswer.class);
when(migAnswerMock.getResult()).thenReturn(true);
when(agentMgr.send(anyLong(), isA(MigrateWithStorageCommand.class))).thenReturn(migAnswerMock);
strategy.copyAsync(volumeMap, to, srcHost, destHost, caller);
assertTrue("Migration across cluster isn't successful.", result.isSuccess());
}
use of org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo in project cloudstack by apache.
the class VmwareStorageMotionStrategyTest method testMigrateAcrossClusterFailure.
@Test
public void testMigrateAcrossClusterFailure() throws Exception {
Host srcHost = mock(Host.class);
Host destHost = mock(Host.class);
when(srcHost.getClusterId()).thenReturn(1L);
when(destHost.getClusterId()).thenReturn(2L);
Map<VolumeInfo, DataStore> volumeMap = new HashMap<VolumeInfo, DataStore>();
VirtualMachineTO to = mock(VirtualMachineTO.class);
when(to.getId()).thenReturn(6L);
VMInstanceVO instance = mock(VMInstanceVO.class);
when(instanceDao.findById(6L)).thenReturn(instance);
MockContext<CommandResult> context = new MockContext<CommandResult>(null, null, volumeMap);
AsyncCallbackDispatcher<VmwareStorageMotionStrategyTest, CopyCommandResult> caller = AsyncCallbackDispatcher.create(this);
caller.setCallback(caller.getTarget().mockCallBack(null, null)).setContext(context);
MigrateWithStorageAnswer migAnswerMock = mock(MigrateWithStorageAnswer.class);
when(migAnswerMock.getResult()).thenReturn(false);
when(agentMgr.send(anyLong(), isA(MigrateWithStorageCommand.class))).thenReturn(migAnswerMock);
strategy.copyAsync(volumeMap, to, srcHost, destHost, caller);
assertFalse("Migration across cluster didn't fail.", result.isSuccess());
}
Aggregations