Search in sources :

Example 76 with Pair

use of com.cloud.legacymodel.utils.Pair 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());
    }
}
Also used : MigrateWithStorageReceiveAnswer(com.cloud.legacymodel.communication.answer.MigrateWithStorageReceiveAnswer) OperationTimedoutException(com.cloud.legacymodel.exceptions.OperationTimedoutException) MigrateWithStorageSendAnswer(com.cloud.legacymodel.communication.answer.MigrateWithStorageSendAnswer) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) AgentUnavailableException(com.cloud.legacymodel.exceptions.AgentUnavailableException) MigrateWithStorageCompleteCommand(com.cloud.legacymodel.communication.command.MigrateWithStorageCompleteCommand) MigrateWithStorageSendCommand(com.cloud.legacymodel.communication.command.MigrateWithStorageSendCommand) MigrateWithStorageCompleteAnswer(com.cloud.legacymodel.communication.answer.MigrateWithStorageCompleteAnswer) Pair(com.cloud.legacymodel.utils.Pair) MigrateWithStorageReceiveCommand(com.cloud.legacymodel.communication.command.MigrateWithStorageReceiveCommand)

Example 77 with Pair

use of com.cloud.legacymodel.utils.Pair 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 78 with Pair

use of com.cloud.legacymodel.utils.Pair in project cosmic by MissionCriticalCloud.

the class KVMStorageMotionStrategy method migrateVmWithVolumesAcrossCluster.

@Override
protected Answer migrateVmWithVolumesAcrossCluster(final VMInstanceVO instanceTo, final VirtualMachineTO vmTo, final Host srcHost, final Host destHost, final Map<VolumeInfo, DataStore> volumeToPoolMap) throws AgentUnavailableException {
    try {
        final List<Pair<VolumeTO, StorageFilerTO>> volumeMapping = buildVolumeMapping(volumeToPoolMap);
        final MigrateWithStorageAcrossClustersCommand command = new MigrateWithStorageAcrossClustersCommand(vmTo, volumeMapping, destHost.getPrivateIpAddress());
        final MigrateWithStorageAcrossClustersAnswer answer = (MigrateWithStorageAcrossClustersAnswer) agentMgr.send(srcHost.getId(), command);
        if (answer == null) {
            final String errorMessage = String.format("Error when trying to migrate VM %s (with storage) to host %s", instanceTo, destHost);
            s_logger.error(errorMessage);
            throw new CloudRuntimeException(errorMessage);
        } else if (!answer.getResult()) {
            final String errorMessage = String.format("Error when trying to migrate VM %s (with storage) to host %s => Details: %s", instanceTo, destHost, answer.getDetails());
            s_logger.error(errorMessage);
            throw new CloudRuntimeException(errorMessage);
        } else {
            // Update the volume details after migration.
            updateVolumePathsAfterMigration(volumeToPoolMap, answer.getVolumes());
        }
        return answer;
    } catch (final OperationTimedoutException e) {
        final String errorMessage = String.format("Operation timed out when attempting to migrate VM %s to host %s", instanceTo, destHost);
        s_logger.error(errorMessage, e);
        throw new AgentUnavailableException(errorMessage, srcHost.getId());
    }
}
Also used : OperationTimedoutException(com.cloud.legacymodel.exceptions.OperationTimedoutException) MigrateWithStorageAcrossClustersAnswer(com.cloud.legacymodel.communication.answer.MigrateWithStorageAcrossClustersAnswer) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) AgentUnavailableException(com.cloud.legacymodel.exceptions.AgentUnavailableException) MigrateWithStorageAcrossClustersCommand(com.cloud.legacymodel.communication.command.MigrateWithStorageAcrossClustersCommand) Pair(com.cloud.legacymodel.utils.Pair)

Example 79 with Pair

use of com.cloud.legacymodel.utils.Pair in project cosmic by MissionCriticalCloud.

the class XenServer610WrapperTest method testMigrateWithStorageReceiveCommand.

@Test
public void testMigrateWithStorageReceiveCommand() {
    final String vmName = "small";
    final String uuid = "206b21a7-c6ec-40e2-b5e2-f861b9612f04";
    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 List<Pair<VolumeTO, StorageFilerTO>> volumeToFiler = new ArrayList<>();
    volumeToFiler.add(new Pair<>(vol1, storage1));
    volumeToFiler.add(new Pair<>(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 network = Mockito.mock(Network.class);
    final XsHost xsHost = Mockito.mock(XsHost.class);
    final Network nw1 = Mockito.mock(Network.class);
    final Network nw2 = Mockito.mock(Network.class);
    final Network nw3 = Mockito.mock(Network.class);
    final SR sr1 = Mockito.mock(SR.class);
    final SR sr2 = Mockito.mock(SR.class);
    final MigrateWithStorageReceiveCommand migrateStorageCommand = new MigrateWithStorageReceiveCommand(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(xenServer610Resource.getStorageRepository(conn, storage1.getUuid())).thenReturn(sr1);
    when(xenServer610Resource.getStorageRepository(conn, storage2.getUuid())).thenReturn(sr2);
    try {
        when(xenServer610Resource.getNetwork(conn, nicTO1)).thenReturn(nw1);
        when(xenServer610Resource.getNetwork(conn, nicTO2)).thenReturn(nw2);
        when(xenServer610Resource.getNetwork(conn, nicTO3)).thenReturn(nw3);
        when(xenServer610Resource.getNativeNetworkForTraffic(conn, TrafficType.Storage, null)).thenReturn(nativeNetworkForTraffic);
        when(nativeNetworkForTraffic.getNetwork()).thenReturn(network);
        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)).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) Connection(com.xensource.xenapi.Connection) ArrayList(java.util.ArrayList) XenAPIException(com.xensource.xenapi.Types.XenAPIException) StorageFilerTO(com.cloud.legacymodel.to.StorageFilerTO) VirtualMachineTO(com.cloud.legacymodel.to.VirtualMachineTO) MigrateWithStorageReceiveCommand(com.cloud.legacymodel.communication.command.MigrateWithStorageReceiveCommand) 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) XmlRpcException(org.apache.xmlrpc.XmlRpcException) Pair(com.cloud.legacymodel.utils.Pair) NicTO(com.cloud.legacymodel.to.NicTO) SR(com.xensource.xenapi.SR) Test(org.junit.Test)

Example 80 with Pair

use of com.cloud.legacymodel.utils.Pair 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());
}
Also used : HashMap(java.util.HashMap) Connection(com.xensource.xenapi.Connection) ArrayList(java.util.ArrayList) VirtualMachineTO(com.cloud.legacymodel.to.VirtualMachineTO) Answer(com.cloud.legacymodel.communication.answer.Answer) VolumeTO(com.cloud.legacymodel.to.VolumeTO) MigrateWithStorageSendCommand(com.cloud.legacymodel.communication.command.MigrateWithStorageSendCommand) Pair(com.cloud.legacymodel.utils.Pair) Test(org.junit.Test)

Aggregations

Pair (com.cloud.legacymodel.utils.Pair)139 ArrayList (java.util.ArrayList)87 List (java.util.List)64 Account (com.cloud.legacymodel.user.Account)49 Filter (com.cloud.utils.db.Filter)48 InvalidParameterValueException (com.cloud.legacymodel.exceptions.InvalidParameterValueException)38 CloudRuntimeException (com.cloud.legacymodel.exceptions.CloudRuntimeException)27 HashMap (java.util.HashMap)27 Ternary (com.cloud.legacymodel.utils.Ternary)23 ListProjectResourcesCriteria (com.cloud.projects.Project.ListProjectResourcesCriteria)22 ExcludeList (com.cloud.deploy.DeploymentPlanner.ExcludeList)20 SSHKeyPair (com.cloud.legacymodel.user.SSHKeyPair)16 TemplateFilter (com.cloud.legacymodel.storage.VirtualMachineTemplate.TemplateFilter)13 Map (java.util.Map)13 DB (com.cloud.utils.db.DB)11 DomainVO (com.cloud.domain.DomainVO)10 VolumeVO (com.cloud.storage.VolumeVO)10 PermissionDeniedException (com.cloud.legacymodel.exceptions.PermissionDeniedException)9 Network (com.cloud.legacymodel.network.Network)9 ResourceTagVO (com.cloud.tags.ResourceTagVO)9