Search in sources :

Example 1 with MigrateWithStorageCommand

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());
    }
}
Also used : MigrateWithStorageAnswer(com.cloud.legacymodel.communication.answer.MigrateWithStorageAnswer) OperationTimedoutException(com.cloud.legacymodel.exceptions.OperationTimedoutException) MigrateWithStorageCommand(com.cloud.legacymodel.communication.command.MigrateWithStorageCommand) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) AgentUnavailableException(com.cloud.legacymodel.exceptions.AgentUnavailableException) Pair(com.cloud.legacymodel.utils.Pair)

Example 2 with MigrateWithStorageCommand

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());
}
Also used : XsHost(com.cloud.hypervisor.xenserver.resource.XsHost) MigrateWithStorageCommand(com.cloud.legacymodel.communication.command.MigrateWithStorageCommand) HashMap(java.util.HashMap) Connection(com.xensource.xenapi.Connection) XenAPIException(com.xensource.xenapi.Types.XenAPIException) StorageFilerTO(com.cloud.legacymodel.to.StorageFilerTO) VirtualMachineTO(com.cloud.legacymodel.to.VirtualMachineTO) Answer(com.cloud.legacymodel.communication.answer.Answer) VolumeTO(com.cloud.legacymodel.to.VolumeTO) XsLocalNetwork(com.cloud.hypervisor.xenserver.resource.XsLocalNetwork) Network(com.xensource.xenapi.Network) XsLocalNetwork(com.cloud.hypervisor.xenserver.resource.XsLocalNetwork) VDI(com.xensource.xenapi.VDI) XmlRpcException(org.apache.xmlrpc.XmlRpcException) NicTO(com.cloud.legacymodel.to.NicTO) SR(com.xensource.xenapi.SR) Test(org.junit.Test)

Aggregations

MigrateWithStorageCommand (com.cloud.legacymodel.communication.command.MigrateWithStorageCommand)2 XsHost (com.cloud.hypervisor.xenserver.resource.XsHost)1 XsLocalNetwork (com.cloud.hypervisor.xenserver.resource.XsLocalNetwork)1 Answer (com.cloud.legacymodel.communication.answer.Answer)1 MigrateWithStorageAnswer (com.cloud.legacymodel.communication.answer.MigrateWithStorageAnswer)1 AgentUnavailableException (com.cloud.legacymodel.exceptions.AgentUnavailableException)1 CloudRuntimeException (com.cloud.legacymodel.exceptions.CloudRuntimeException)1 OperationTimedoutException (com.cloud.legacymodel.exceptions.OperationTimedoutException)1 NicTO (com.cloud.legacymodel.to.NicTO)1 StorageFilerTO (com.cloud.legacymodel.to.StorageFilerTO)1 VirtualMachineTO (com.cloud.legacymodel.to.VirtualMachineTO)1 VolumeTO (com.cloud.legacymodel.to.VolumeTO)1 Pair (com.cloud.legacymodel.utils.Pair)1 Connection (com.xensource.xenapi.Connection)1 Network (com.xensource.xenapi.Network)1 SR (com.xensource.xenapi.SR)1 XenAPIException (com.xensource.xenapi.Types.XenAPIException)1 VDI (com.xensource.xenapi.VDI)1 HashMap (java.util.HashMap)1 XmlRpcException (org.apache.xmlrpc.XmlRpcException)1