Search in sources :

Example 1 with MigrateWithStorageCompleteCommand

use of com.cloud.legacymodel.communication.command.MigrateWithStorageCompleteCommand 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 2 with MigrateWithStorageCompleteCommand

use of com.cloud.legacymodel.communication.command.MigrateWithStorageCompleteCommand in project cosmic by MissionCriticalCloud.

the class XenServer610WrapperTest method testMigrateWithStorageCompleteCommand.

@Test
public void testMigrateWithStorageCompleteCommand() {
    final String vmName = "small";
    final String uuid = "206b21a7-c6ec-40e2-b5e2-f861b9612f04";
    final Connection conn = Mockito.mock(Connection.class);
    final XsHost xsHost = Mockito.mock(XsHost.class);
    final VirtualMachineTO vm = Mockito.mock(VirtualMachineTO.class);
    final MigrateWithStorageCompleteCommand createStorageCommand = new MigrateWithStorageCompleteCommand(vm);
    final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
    assertNotNull(wrapper);
    when(xenServer610Resource.getConnection()).thenReturn(conn);
    when(vm.getName()).thenReturn(vmName);
    when(xenServer610Resource.getHost()).thenReturn(xsHost);
    when(xsHost.getUuid()).thenReturn(uuid);
    final Answer answer = wrapper.execute(createStorageCommand, xenServer610Resource);
    verify(xenServer610Resource, times(1)).getConnection();
    assertFalse(answer.getResult());
}
Also used : Answer(com.cloud.legacymodel.communication.answer.Answer) XsHost(com.cloud.hypervisor.xenserver.resource.XsHost) Connection(com.xensource.xenapi.Connection) MigrateWithStorageCompleteCommand(com.cloud.legacymodel.communication.command.MigrateWithStorageCompleteCommand) VirtualMachineTO(com.cloud.legacymodel.to.VirtualMachineTO) Test(org.junit.Test)

Aggregations

MigrateWithStorageCompleteCommand (com.cloud.legacymodel.communication.command.MigrateWithStorageCompleteCommand)2 XsHost (com.cloud.hypervisor.xenserver.resource.XsHost)1 Answer (com.cloud.legacymodel.communication.answer.Answer)1 MigrateWithStorageCompleteAnswer (com.cloud.legacymodel.communication.answer.MigrateWithStorageCompleteAnswer)1 MigrateWithStorageReceiveAnswer (com.cloud.legacymodel.communication.answer.MigrateWithStorageReceiveAnswer)1 MigrateWithStorageSendAnswer (com.cloud.legacymodel.communication.answer.MigrateWithStorageSendAnswer)1 MigrateWithStorageReceiveCommand (com.cloud.legacymodel.communication.command.MigrateWithStorageReceiveCommand)1 MigrateWithStorageSendCommand (com.cloud.legacymodel.communication.command.MigrateWithStorageSendCommand)1 AgentUnavailableException (com.cloud.legacymodel.exceptions.AgentUnavailableException)1 CloudRuntimeException (com.cloud.legacymodel.exceptions.CloudRuntimeException)1 OperationTimedoutException (com.cloud.legacymodel.exceptions.OperationTimedoutException)1 VirtualMachineTO (com.cloud.legacymodel.to.VirtualMachineTO)1 Pair (com.cloud.legacymodel.utils.Pair)1 Connection (com.xensource.xenapi.Connection)1 Test (org.junit.Test)1