use of com.cloud.legacymodel.communication.command.MigrateWithStorageCommand in project cosmic by MissionCriticalCloud.
the class AbstractHyperVisorStorageMotionStrategy method migrateVmWithVolumesWithinCluster.
private Answer migrateVmWithVolumesWithinCluster(final VMInstanceVO vm, final VirtualMachineTO to, final Host srcHost, final Host destHost, final Map<VolumeInfo, DataStore> volumeToPool) throws AgentUnavailableException {
// Initiate migration of a virtual machine with it's volumes.
try {
final List<Pair<VolumeTO, StorageFilerTO>> volumeToFilerto = buildVolumeMapping(volumeToPool);
final MigrateWithStorageCommand command = new MigrateWithStorageCommand(to, volumeToFilerto, destHost.getGuid());
final MigrateWithStorageAnswer answer = (MigrateWithStorageAnswer) agentMgr.send(destHost.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.
updateVolumePathsAfterMigration(volumeToPool, answer.getVolumeTos());
}
return answer;
} catch (final 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 com.cloud.legacymodel.communication.command.MigrateWithStorageCommand in project cosmic by MissionCriticalCloud.
the class XenServer610WrapperTest method testMigrateWithStorageCommand.
@Test
public void testMigrateWithStorageCommand() {
final String vmName = "small";
final String uuid = "206b21a7-c6ec-40e2-b5e2-f861b9612f04";
final String path = "/";
final Connection conn = Mockito.mock(Connection.class);
final VirtualMachineTO vmSpec = Mockito.mock(VirtualMachineTO.class);
final VolumeTO vol1 = Mockito.mock(VolumeTO.class);
final VolumeTO vol2 = Mockito.mock(VolumeTO.class);
final StorageFilerTO storage1 = Mockito.mock(StorageFilerTO.class);
final StorageFilerTO storage2 = Mockito.mock(StorageFilerTO.class);
final Map<VolumeTO, StorageFilerTO> volumeToFiler = new HashMap<>();
volumeToFiler.put(vol1, storage1);
volumeToFiler.put(vol2, storage2);
final NicTO nicTO1 = Mockito.mock(NicTO.class);
final NicTO nicTO2 = Mockito.mock(NicTO.class);
final NicTO nicTO3 = Mockito.mock(NicTO.class);
final NicTO[] nicTOs = { nicTO1, nicTO2, nicTO3 };
final XsLocalNetwork nativeNetworkForTraffic = Mockito.mock(XsLocalNetwork.class);
final Network networkForSm = Mockito.mock(Network.class);
final XsHost xsHost = Mockito.mock(XsHost.class);
final SR sr1 = Mockito.mock(SR.class);
final SR sr2 = Mockito.mock(SR.class);
final VDI vdi1 = Mockito.mock(VDI.class);
final VDI vdi2 = Mockito.mock(VDI.class);
final MigrateWithStorageCommand migrateStorageCommand = new MigrateWithStorageCommand(vmSpec, volumeToFiler);
final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
assertNotNull(wrapper);
when(xenServer610Resource.getConnection()).thenReturn(conn);
when(vmSpec.getName()).thenReturn(vmName);
when(vmSpec.getNics()).thenReturn(nicTOs);
when(storage1.getUuid()).thenReturn(uuid);
when(storage2.getUuid()).thenReturn(uuid);
when(vol1.getPath()).thenReturn(path);
when(vol2.getPath()).thenReturn(path);
when(xenServer610Resource.getStorageRepository(conn, storage1.getUuid())).thenReturn(sr1);
when(xenServer610Resource.getStorageRepository(conn, storage2.getUuid())).thenReturn(sr2);
when(xenServer610Resource.getVDIbyUuid(conn, storage1.getPath())).thenReturn(vdi1);
when(xenServer610Resource.getVDIbyUuid(conn, storage2.getPath())).thenReturn(vdi2);
try {
when(xenServer610Resource.getNativeNetworkForTraffic(conn, TrafficType.Storage, null)).thenReturn(nativeNetworkForTraffic);
when(nativeNetworkForTraffic.getNetwork()).thenReturn(networkForSm);
when(xenServer610Resource.getHost()).thenReturn(xsHost);
when(xsHost.getUuid()).thenReturn(uuid);
} catch (final XenAPIException e) {
fail(e.getMessage());
} catch (final XmlRpcException e) {
fail(e.getMessage());
}
final Answer answer = wrapper.execute(migrateStorageCommand, xenServer610Resource);
verify(xenServer610Resource, times(1)).getConnection();
try {
verify(xenServer610Resource, times(1)).prepareISO(conn, vmName, null, null);
verify(xenServer610Resource, times(1)).getNetwork(conn, nicTO1);
verify(xenServer610Resource, times(1)).getNetwork(conn, nicTO2);
verify(xenServer610Resource, times(1)).getNetwork(conn, nicTO3);
verify(xenServer610Resource, times(1)).getNativeNetworkForTraffic(conn, TrafficType.Storage, null);
verify(nativeNetworkForTraffic, times(1)).getNetwork();
verify(xenServer610Resource, times(1)).getHost();
verify(xsHost, times(1)).getUuid();
} catch (final XenAPIException e) {
fail(e.getMessage());
} catch (final XmlRpcException e) {
fail(e.getMessage());
}
assertFalse(answer.getResult());
}
Aggregations