Search in sources :

Example 81 with VolumeInfo

use of org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo in project cloudstack by apache.

the class VmwareStorageMotionStrategyTest method testStrategyHandlesVmwareHosts.

@Test
public void testStrategyHandlesVmwareHosts() throws Exception {
    Host srcHost = mock(Host.class);
    Host destHost = mock(Host.class);
    when(srcHost.getHypervisorType()).thenReturn(HypervisorType.VMware);
    when(destHost.getHypervisorType()).thenReturn(HypervisorType.VMware);
    Map<VolumeInfo, DataStore> volumeMap = new HashMap<VolumeInfo, DataStore>();
    StrategyPriority canHandle = strategy.canHandle(volumeMap, srcHost, destHost);
    assertTrue("The strategy is only supposed to handle vmware hosts", canHandle == StrategyPriority.HYPERVISOR);
}
Also used : HashMap(java.util.HashMap) StrategyPriority(org.apache.cloudstack.engine.subsystem.api.storage.StrategyPriority) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) Host(com.cloud.host.Host) VolumeInfo(org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo) Test(org.junit.Test)

Example 82 with VolumeInfo

use of org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo in project cloudstack by apache.

the class VmwareStorageMotionStrategy method migrateVmWithVolumesWithinCluster.

private Answer migrateVmWithVolumesWithinCluster(VMInstanceVO vm, VirtualMachineTO to, Host srcHost, Host destHost, Map<VolumeInfo, DataStore> volumeToPool) throws AgentUnavailableException {
    // Initiate migration of a virtual machine with it's volumes.
    try {
        List<Pair<VolumeTO, StorageFilerTO>> volumeToFilerto = new ArrayList<Pair<VolumeTO, StorageFilerTO>>();
        for (Map.Entry<VolumeInfo, DataStore> entry : volumeToPool.entrySet()) {
            VolumeInfo volume = entry.getKey();
            VolumeTO volumeTo = new VolumeTO(volume, storagePoolDao.findById(volume.getPoolId()));
            StorageFilerTO filerTo = new StorageFilerTO((StoragePool) entry.getValue());
            volumeToFilerto.add(new Pair<VolumeTO, StorageFilerTO>(volumeTo, filerTo));
        }
        MigrateWithStorageCommand command = new MigrateWithStorageCommand(to, volumeToFilerto, destHost.getGuid());
        MigrateWithStorageAnswer answer = (MigrateWithStorageAnswer) agentMgr.send(srcHost.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.
            updateVolumesAfterMigration(volumeToPool, answer.getVolumeTos());
        }
        return answer;
    } catch (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.agent.api.MigrateWithStorageAnswer) OperationTimedoutException(com.cloud.exception.OperationTimedoutException) MigrateWithStorageCommand(com.cloud.agent.api.MigrateWithStorageCommand) ArrayList(java.util.ArrayList) VolumeInfo(org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo) StorageFilerTO(com.cloud.agent.api.to.StorageFilerTO) VolumeTO(com.cloud.agent.api.to.VolumeTO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) Map(java.util.Map) Pair(com.cloud.utils.Pair)

Example 83 with VolumeInfo

use of org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo in project cloudstack by apache.

the class VmwareStorageMotionStrategyTest method testMigrateWithinClusterSuccess.

@Test
public void testMigrateWithinClusterSuccess() throws Exception {
    Host srcHost = mock(Host.class);
    Host destHost = mock(Host.class);
    when(srcHost.getClusterId()).thenReturn(1L);
    when(destHost.getClusterId()).thenReturn(1L);
    Map<VolumeInfo, DataStore> volumeMap = new HashMap<VolumeInfo, DataStore>();
    VirtualMachineTO to = mock(VirtualMachineTO.class);
    when(to.getId()).thenReturn(6L);
    VMInstanceVO instance = mock(VMInstanceVO.class);
    when(instanceDao.findById(6L)).thenReturn(instance);
    MockContext<CommandResult> context = new MockContext<CommandResult>(null, null, volumeMap);
    AsyncCallbackDispatcher<VmwareStorageMotionStrategyTest, CopyCommandResult> caller = AsyncCallbackDispatcher.create(this);
    caller.setCallback(caller.getTarget().mockCallBack(null, null)).setContext(context);
    MigrateWithStorageAnswer migAnswerMock = mock(MigrateWithStorageAnswer.class);
    when(migAnswerMock.getResult()).thenReturn(true);
    when(agentMgr.send(anyLong(), isA(MigrateWithStorageCommand.class))).thenReturn(migAnswerMock);
    strategy.copyAsync(volumeMap, to, srcHost, destHost, caller);
    assertTrue("Migration within cluster isn't successful.", result.isSuccess());
}
Also used : MigrateWithStorageAnswer(com.cloud.agent.api.MigrateWithStorageAnswer) MigrateWithStorageCommand(com.cloud.agent.api.MigrateWithStorageCommand) HashMap(java.util.HashMap) VMInstanceVO(com.cloud.vm.VMInstanceVO) Host(com.cloud.host.Host) VolumeInfo(org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo) VirtualMachineTO(com.cloud.agent.api.to.VirtualMachineTO) CommandResult(org.apache.cloudstack.storage.command.CommandResult) CopyCommandResult(org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) CopyCommandResult(org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult) Test(org.junit.Test)

Example 84 with VolumeInfo

use of org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo in project cloudstack by apache.

the class VmwareStorageMotionStrategyTest method testMigrateAcrossClusterSuccess.

@Test
public void testMigrateAcrossClusterSuccess() throws Exception {
    Host srcHost = mock(Host.class);
    Host destHost = mock(Host.class);
    when(srcHost.getClusterId()).thenReturn(1L);
    when(destHost.getClusterId()).thenReturn(2L);
    Map<VolumeInfo, DataStore> volumeMap = new HashMap<VolumeInfo, DataStore>();
    VirtualMachineTO to = mock(VirtualMachineTO.class);
    when(to.getId()).thenReturn(6L);
    VMInstanceVO instance = mock(VMInstanceVO.class);
    when(instanceDao.findById(6L)).thenReturn(instance);
    MockContext<CommandResult> context = new MockContext<CommandResult>(null, null, volumeMap);
    AsyncCallbackDispatcher<VmwareStorageMotionStrategyTest, CopyCommandResult> caller = AsyncCallbackDispatcher.create(this);
    caller.setCallback(caller.getTarget().mockCallBack(null, null)).setContext(context);
    MigrateWithStorageAnswer migAnswerMock = mock(MigrateWithStorageAnswer.class);
    when(migAnswerMock.getResult()).thenReturn(true);
    when(agentMgr.send(anyLong(), isA(MigrateWithStorageCommand.class))).thenReturn(migAnswerMock);
    strategy.copyAsync(volumeMap, to, srcHost, destHost, caller);
    assertTrue("Migration across cluster isn't successful.", result.isSuccess());
}
Also used : MigrateWithStorageAnswer(com.cloud.agent.api.MigrateWithStorageAnswer) MigrateWithStorageCommand(com.cloud.agent.api.MigrateWithStorageCommand) HashMap(java.util.HashMap) VMInstanceVO(com.cloud.vm.VMInstanceVO) Host(com.cloud.host.Host) VolumeInfo(org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo) VirtualMachineTO(com.cloud.agent.api.to.VirtualMachineTO) CommandResult(org.apache.cloudstack.storage.command.CommandResult) CopyCommandResult(org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) CopyCommandResult(org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult) Test(org.junit.Test)

Example 85 with VolumeInfo

use of org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo in project cloudstack by apache.

the class VmwareStorageMotionStrategyTest method testMigrateAcrossClusterFailure.

@Test
public void testMigrateAcrossClusterFailure() throws Exception {
    Host srcHost = mock(Host.class);
    Host destHost = mock(Host.class);
    when(srcHost.getClusterId()).thenReturn(1L);
    when(destHost.getClusterId()).thenReturn(2L);
    Map<VolumeInfo, DataStore> volumeMap = new HashMap<VolumeInfo, DataStore>();
    VirtualMachineTO to = mock(VirtualMachineTO.class);
    when(to.getId()).thenReturn(6L);
    VMInstanceVO instance = mock(VMInstanceVO.class);
    when(instanceDao.findById(6L)).thenReturn(instance);
    MockContext<CommandResult> context = new MockContext<CommandResult>(null, null, volumeMap);
    AsyncCallbackDispatcher<VmwareStorageMotionStrategyTest, CopyCommandResult> caller = AsyncCallbackDispatcher.create(this);
    caller.setCallback(caller.getTarget().mockCallBack(null, null)).setContext(context);
    MigrateWithStorageAnswer migAnswerMock = mock(MigrateWithStorageAnswer.class);
    when(migAnswerMock.getResult()).thenReturn(false);
    when(agentMgr.send(anyLong(), isA(MigrateWithStorageCommand.class))).thenReturn(migAnswerMock);
    strategy.copyAsync(volumeMap, to, srcHost, destHost, caller);
    assertFalse("Migration across cluster didn't fail.", result.isSuccess());
}
Also used : MigrateWithStorageAnswer(com.cloud.agent.api.MigrateWithStorageAnswer) MigrateWithStorageCommand(com.cloud.agent.api.MigrateWithStorageCommand) HashMap(java.util.HashMap) VMInstanceVO(com.cloud.vm.VMInstanceVO) Host(com.cloud.host.Host) VolumeInfo(org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo) VirtualMachineTO(com.cloud.agent.api.to.VirtualMachineTO) CommandResult(org.apache.cloudstack.storage.command.CommandResult) CopyCommandResult(org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) CopyCommandResult(org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult) Test(org.junit.Test)

Aggregations

VolumeInfo (org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo)112 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)51 DataStore (org.apache.cloudstack.engine.subsystem.api.storage.DataStore)50 VolumeVO (com.cloud.storage.VolumeVO)36 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)23 ResourceAllocationException (com.cloud.exception.ResourceAllocationException)22 ExecutionException (java.util.concurrent.ExecutionException)22 VolumeApiResult (org.apache.cloudstack.engine.subsystem.api.storage.VolumeService.VolumeApiResult)22 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)19 StoragePoolVO (org.apache.cloudstack.storage.datastore.db.StoragePoolVO)19 CopyCommandResult (org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult)18 SnapshotInfo (org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo)17 ArrayList (java.util.ArrayList)15 HashMap (java.util.HashMap)15 StorageUnavailableException (com.cloud.exception.StorageUnavailableException)13 Map (java.util.Map)13 SnapshotVO (com.cloud.storage.SnapshotVO)12 DB (com.cloud.utils.db.DB)12 Test (org.testng.annotations.Test)12 Account (com.cloud.user.Account)11