use of com.cloud.legacymodel.communication.command.MigrateWithStorageSendCommand in project cosmic by MissionCriticalCloud.
the class XenServerStorageMotionStrategy method migrateVmWithVolumesAcrossCluster.
@Override
protected Answer migrateVmWithVolumesAcrossCluster(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);
// Migration across cluster needs to be done in three phases.
// 1. Send a migrate receive command to the destination host so that it is ready to receive a vm.
// 2. Send a migrate send command to the source host. This actually migrates the vm to the destination.
// 3. Complete the process. Update the volume details.
final MigrateWithStorageReceiveCommand receiveCmd = new MigrateWithStorageReceiveCommand(to, volumeToFilerto);
final MigrateWithStorageReceiveAnswer receiveAnswer = (MigrateWithStorageReceiveAnswer) agentMgr.send(destHost.getId(), receiveCmd);
if (receiveAnswer == null) {
s_logger.error("Migration with storage of vm " + vm + " to host " + destHost + " failed.");
throw new CloudRuntimeException("Error while migrating the vm " + vm + " to host " + destHost);
} else if (!receiveAnswer.getResult()) {
s_logger.error("Migration with storage of vm " + vm + " failed. Details: " + receiveAnswer.getDetails());
throw new CloudRuntimeException("Error while migrating the vm " + vm + " to host " + destHost);
}
final MigrateWithStorageSendCommand sendCmd = new MigrateWithStorageSendCommand(to, receiveAnswer.getVolumeToSr(), receiveAnswer.getNicToNetwork(), receiveAnswer.getToken());
final MigrateWithStorageSendAnswer sendAnswer = (MigrateWithStorageSendAnswer) agentMgr.send(srcHost.getId(), sendCmd);
if (sendAnswer == null) {
s_logger.error("Migration with storage of vm " + vm + " to host " + destHost + " failed.");
throw new CloudRuntimeException("Error while migrating the vm " + vm + " to host " + destHost);
} else if (!sendAnswer.getResult()) {
s_logger.error("Migration with storage of vm " + vm + " failed. Details: " + sendAnswer.getDetails());
throw new CloudRuntimeException("Error while migrating the vm " + vm + " to host " + destHost);
}
final MigrateWithStorageCompleteCommand command = new MigrateWithStorageCompleteCommand(to);
final MigrateWithStorageCompleteAnswer answer = (MigrateWithStorageCompleteAnswer) 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);
} 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.MigrateWithStorageSendCommand in project cosmic by MissionCriticalCloud.
the class XenServer610WrapperTest method testMigrateWithStorageSendCommandNetException.
@Test
public void testMigrateWithStorageSendCommandNetException() {
final String vmName = "small";
final String path = "/";
final Connection conn = Mockito.mock(Connection.class);
final VirtualMachineTO vmSpec = Mockito.mock(VirtualMachineTO.class);
final VolumeTO volume1 = Mockito.mock(VolumeTO.class);
final VolumeTO volume2 = Mockito.mock(VolumeTO.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 NicTO nic1 = Mockito.mock(NicTO.class);
final NicTO nic2 = Mockito.mock(NicTO.class);
final Gson gson = new Gson();
final List<Pair<VolumeTO, Object>> volumeToSr = new ArrayList<>();
volumeToSr.add(new Pair<>(volume1, sr1));
volumeToSr.add(new Pair<>(volume2, sr2));
final List<Pair<NicTO, Object>> nicToNetwork = new ArrayList<>();
nicToNetwork.add(new Pair<>(nic1, new String("a")));
nicToNetwork.add(new Pair<>(nic2, new String("b")));
final Map<String, String> token = new HashMap<>();
final MigrateWithStorageSendCommand migrateStorageCommand = new MigrateWithStorageSendCommand(vmSpec, volumeToSr, nicToNetwork, token);
final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
assertNotNull(wrapper);
when(xenServer610Resource.getConnection()).thenReturn(conn);
when(vmSpec.getName()).thenReturn(vmName);
when(volume1.getPath()).thenReturn(path);
when(volume2.getPath()).thenReturn(path);
when(xenServer610Resource.getVDIbyUuid(conn, volume1.getPath())).thenReturn(vdi1);
when(xenServer610Resource.getVDIbyUuid(conn, volume2.getPath())).thenReturn(vdi2);
final Answer answer = wrapper.execute(migrateStorageCommand, xenServer610Resource);
verify(xenServer610Resource, times(1)).getConnection();
assertFalse(answer.getResult());
}
use of com.cloud.legacymodel.communication.command.MigrateWithStorageSendCommand in project cosmic by MissionCriticalCloud.
the class XenServer610WrapperTest method testMigrateWithStorageSendCommand.
@Test
public void testMigrateWithStorageSendCommand() {
final String vmName = "small";
final String path = "/";
final String mac = "3c:15:c2:c4:4f:18";
final Connection conn = Mockito.mock(Connection.class);
final VirtualMachineTO vmSpec = Mockito.mock(VirtualMachineTO.class);
final VolumeTO volume1 = Mockito.mock(VolumeTO.class);
final VolumeTO volume2 = Mockito.mock(VolumeTO.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 NicTO nic1 = Mockito.mock(NicTO.class);
final NicTO nic2 = Mockito.mock(NicTO.class);
final Network network1 = Mockito.mock(Network.class);
final Network network2 = Mockito.mock(Network.class);
final List<Pair<VolumeTO, Object>> volumeToSr = new ArrayList<>();
volumeToSr.add(new Pair<>(volume1, sr1));
volumeToSr.add(new Pair<>(volume2, sr2));
final List<Pair<NicTO, Object>> nicToNetwork = new ArrayList<>();
nicToNetwork.add(new Pair<>(nic1, network1));
nicToNetwork.add(new Pair<>(nic2, network2));
final Map<String, String> token = new HashMap<>();
final VIF vif1 = Mockito.mock(VIF.class);
final VIF vif2 = Mockito.mock(VIF.class);
final MigrateWithStorageSendCommand migrateStorageCommand = new MigrateWithStorageSendCommand(vmSpec, volumeToSr, nicToNetwork, token);
final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
assertNotNull(wrapper);
when(xenServer610Resource.getConnection()).thenReturn(conn);
when(vmSpec.getName()).thenReturn(vmName);
when(volume1.getPath()).thenReturn(path);
when(volume2.getPath()).thenReturn(path);
when(nic1.getMac()).thenReturn(mac);
when(nic2.getMac()).thenReturn(mac);
when(xenServer610Resource.getVDIbyUuid(conn, volume1.getPath())).thenReturn(vdi1);
when(xenServer610Resource.getVDIbyUuid(conn, volume2.getPath())).thenReturn(vdi2);
try {
when(xenServer610Resource.getVifByMac(conn, null, nic1.getMac())).thenReturn(vif1);
when(xenServer610Resource.getVifByMac(conn, null, nic2.getMac())).thenReturn(vif2);
} 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(2)).getVDIbyUuid(conn, volume1.getPath());
verify(xenServer610Resource, times(2)).getVifByMac(conn, null, nic1.getMac());
} catch (final XenAPIException e) {
fail(e.getMessage());
} catch (final XmlRpcException e) {
fail(e.getMessage());
}
assertFalse(answer.getResult());
}
use of com.cloud.legacymodel.communication.command.MigrateWithStorageSendCommand in project cosmic by MissionCriticalCloud.
the class XenServer610WrapperTest method testMigrateWithStorageSendCommandSRException.
@Test
public void testMigrateWithStorageSendCommandSRException() {
final String vmName = "small";
final Connection conn = Mockito.mock(Connection.class);
final VirtualMachineTO vmSpec = Mockito.mock(VirtualMachineTO.class);
final VolumeTO volume1 = Mockito.mock(VolumeTO.class);
final VolumeTO volume2 = Mockito.mock(VolumeTO.class);
final List<Pair<VolumeTO, Object>> volumeToSr = new ArrayList<>();
volumeToSr.add(new Pair<>(volume1, new String("a")));
volumeToSr.add(new Pair<>(volume2, new String("b")));
final List<Pair<NicTO, Object>> nicToNetwork = new ArrayList<>();
final Map<String, String> token = new HashMap<>();
final MigrateWithStorageSendCommand migrateStorageCommand = new MigrateWithStorageSendCommand(vmSpec, volumeToSr, nicToNetwork, token);
final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
assertNotNull(wrapper);
when(xenServer610Resource.getConnection()).thenReturn(conn);
when(vmSpec.getName()).thenReturn(vmName);
final Answer answer = wrapper.execute(migrateStorageCommand, xenServer610Resource);
verify(xenServer610Resource, times(1)).getConnection();
assertFalse(answer.getResult());
}
Aggregations