Search in sources :

Example 76 with Host

use of com.cloud.host.Host 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 77 with Host

use of com.cloud.host.Host 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 78 with Host

use of com.cloud.host.Host 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 79 with Host

use of com.cloud.host.Host 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)

Example 80 with Host

use of com.cloud.host.Host in project cloudstack by apache.

the class JuniperSRXExternalFirewallElement method createSrxFirewallResponse.

@Override
public SrxFirewallResponse createSrxFirewallResponse(ExternalFirewallDeviceVO fwDeviceVO) {
    SrxFirewallResponse response = new SrxFirewallResponse();
    Map<String, String> fwDetails = _hostDetailDao.findDetails(fwDeviceVO.getHostId());
    Host fwHost = _hostDao.findById(fwDeviceVO.getHostId());
    response.setId(fwDeviceVO.getUuid());
    PhysicalNetwork pnw = ApiDBUtils.findPhysicalNetworkById(fwDeviceVO.getPhysicalNetworkId());
    if (pnw != null) {
        response.setPhysicalNetworkId(pnw.getUuid());
    }
    response.setDeviceName(fwDeviceVO.getDeviceName());
    if (fwDeviceVO.getCapacity() == 0) {
        long defaultFwCapacity = NumbersUtil.parseLong(_configDao.getValue(Config.DefaultExternalFirewallCapacity.key()), 50);
        response.setDeviceCapacity(defaultFwCapacity);
    } else {
        response.setDeviceCapacity(fwDeviceVO.getCapacity());
    }
    response.setProvider(fwDeviceVO.getProviderName());
    response.setDeviceState(fwDeviceVO.getDeviceState().name());
    response.setIpAddress(fwHost.getPrivateIpAddress());
    response.setPublicInterface(fwDetails.get("publicInterface"));
    response.setUsageInterface(fwDetails.get("usageInterface"));
    response.setPrivateInterface(fwDetails.get("privateInterface"));
    response.setPublicZone(fwDetails.get("publicZone"));
    response.setPrivateZone(fwDetails.get("privateZone"));
    response.setNumRetries(fwDetails.get("numRetries"));
    response.setTimeout(fwDetails.get("timeout"));
    response.setObjectName("srxfirewall");
    return response;
}
Also used : PhysicalNetwork(com.cloud.network.PhysicalNetwork) SrxFirewallResponse(com.cloud.api.response.SrxFirewallResponse) Host(com.cloud.host.Host)

Aggregations

Host (com.cloud.host.Host)112 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)37 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)31 ArrayList (java.util.ArrayList)31 HashMap (java.util.HashMap)29 ServerApiException (org.apache.cloudstack.api.ServerApiException)20 ConfigurationException (javax.naming.ConfigurationException)17 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)16 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)16 DB (com.cloud.utils.db.DB)14 Map (java.util.Map)14 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)13 PhysicalNetworkServiceProviderVO (com.cloud.network.dao.PhysicalNetworkServiceProviderVO)13 Answer (com.cloud.agent.api.Answer)11 TransactionStatus (com.cloud.utils.db.TransactionStatus)11 DataCenter (com.cloud.dc.DataCenter)10 AgentUnavailableException (com.cloud.exception.AgentUnavailableException)10 OperationTimedoutException (com.cloud.exception.OperationTimedoutException)10 HostVO (com.cloud.host.HostVO)9 StoragePool (com.cloud.storage.StoragePool)9