Search in sources :

Example 41 with DeployDestination

use of com.cloud.deploy.DeployDestination in project cloudstack by apache.

the class RouterDeploymentDefinition method findOrDeployVirtualRouter.

@DB
protected void findOrDeployVirtualRouter() throws ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException {
    if (!isRouterDeployed()) {
        try {
            lock();
            // reset router list that got populated during isRouterDeployed()
            routers.clear();
            checkPreconditions();
            // dest has pod=null, for Basic Zone findOrDeployVRs for all Pods
            final List<DeployDestination> destinations = findDestinations();
            for (final DeployDestination destination : destinations) {
                dest = destination;
                generateDeploymentPlan();
                executeDeployment();
            }
        } finally {
            unlock();
        }
    }
}
Also used : DeployDestination(com.cloud.deploy.DeployDestination) DB(com.cloud.utils.db.DB)

Example 42 with DeployDestination

use of com.cloud.deploy.DeployDestination in project cloudstack by apache.

the class BrocadeVcsGuestNetworkGuruTest method testImplementFail.

@Test
public void testImplementFail() throws InsufficientVirtualNetworkCapacityException, URISyntaxException {
    final PhysicalNetworkVO physnet = mock(PhysicalNetworkVO.class);
    when(physnetdao.findById((Long) any())).thenReturn(physnet);
    when(physnet.getIsolationMethods()).thenReturn(Arrays.asList(new String[] { "VCS" }));
    when(physnet.getId()).thenReturn(NETWORK_ID);
    final NetworkOffering offering = mock(NetworkOffering.class);
    when(offering.getId()).thenReturn(NETWORK_ID);
    when(offering.getTrafficType()).thenReturn(TrafficType.Guest);
    when(offering.getGuestType()).thenReturn(GuestType.Isolated);
    when(nosd.areServicesSupportedByNetworkOffering(NETWORK_ID, Service.Connectivity)).thenReturn(false);
    mock(DeploymentPlan.class);
    final NetworkVO network = mock(NetworkVO.class);
    when(network.getName()).thenReturn("testnetwork");
    when(network.getState()).thenReturn(State.Implementing);
    when(network.getPhysicalNetworkId()).thenReturn(NETWORK_ID);
    when(network.getBroadcastUri()).thenReturn(new URI("vlan://14"));
    final DeployDestination dest = mock(DeployDestination.class);
    final DataCenter dc = mock(DataCenter.class);
    when(dest.getDataCenter()).thenReturn(dc);
    final HostVO brocadeHost = mock(HostVO.class);
    when(hostdao.findById(anyLong())).thenReturn(brocadeHost);
    when(brocadeHost.getId()).thenReturn(NETWORK_ID);
    when(netmodel.findPhysicalNetworkId(anyLong(), (String) any(), (TrafficType) any())).thenReturn(NETWORK_ID);
    final BrocadeVcsDeviceVO brocadeDevice = mock(BrocadeVcsDeviceVO.class);
    when(brocadeDevice.getHostId()).thenReturn(NETWORK_ID);
    final List<BrocadeVcsDeviceVO> devices = mock(List.class);
    when(devices.isEmpty()).thenReturn(true);
    when(vcsdao.listByPhysicalNetwork(anyLong())).thenReturn(devices);
    final Domain dom = mock(Domain.class);
    when(dom.getName()).thenReturn("domain");
    final Account acc = mock(Account.class);
    when(acc.getAccountName()).thenReturn("accountname");
    final ReservationContext res = mock(ReservationContext.class);
    when(res.getDomain()).thenReturn(dom);
    when(res.getAccount()).thenReturn(acc);
    when(guestGuru.implement(network, offering, dest, res)).thenReturn(network);
    final CreateNetworkAnswer answer = mock(CreateNetworkAnswer.class);
    when(answer.getResult()).thenReturn(true);
    when(agentmgr.easySend(eq(NETWORK_ID), (Command) any())).thenReturn(answer);
    final Network implementednetwork = guru.implement(network, offering, dest, res);
    assertTrue(implementednetwork == null);
    verify(agentmgr, times(0)).easySend(eq(NETWORK_ID), (Command) any());
}
Also used : Account(com.cloud.user.Account) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NetworkVO(com.cloud.network.dao.NetworkVO) NetworkOffering(com.cloud.offering.NetworkOffering) URI(java.net.URI) HostVO(com.cloud.host.HostVO) BrocadeVcsDeviceVO(com.cloud.network.BrocadeVcsDeviceVO) ReservationContext(com.cloud.vm.ReservationContext) DataCenter(com.cloud.dc.DataCenter) DeployDestination(com.cloud.deploy.DeployDestination) CreateNetworkAnswer(com.cloud.agent.api.CreateNetworkAnswer) Network(com.cloud.network.Network) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) Domain(com.cloud.domain.Domain) Test(org.junit.Test)

Example 43 with DeployDestination

use of com.cloud.deploy.DeployDestination in project cloudstack by apache.

the class BrocadeVcsGuestNetworkGuruTest method testImplement.

@Test
public void testImplement() throws InsufficientVirtualNetworkCapacityException, URISyntaxException {
    final PhysicalNetworkVO physnet = mock(PhysicalNetworkVO.class);
    when(physnetdao.findById((Long) any())).thenReturn(physnet);
    when(physnet.getIsolationMethods()).thenReturn(Arrays.asList(new String[] { "VCS" }));
    when(physnet.getId()).thenReturn(NETWORK_ID);
    final NetworkOffering offering = mock(NetworkOffering.class);
    when(offering.getId()).thenReturn(NETWORK_ID);
    when(offering.getTrafficType()).thenReturn(TrafficType.Guest);
    when(offering.getGuestType()).thenReturn(GuestType.Isolated);
    when(nosd.areServicesSupportedByNetworkOffering(NETWORK_ID, Service.Connectivity)).thenReturn(true);
    mock(DeploymentPlan.class);
    final NetworkVO network = mock(NetworkVO.class);
    when(network.getName()).thenReturn("testnetwork");
    when(network.getState()).thenReturn(State.Implementing);
    when(network.getPhysicalNetworkId()).thenReturn(NETWORK_ID);
    when(network.getBroadcastUri()).thenReturn(new URI("vlan://14"));
    final DeployDestination dest = mock(DeployDestination.class);
    final DataCenter dc = mock(DataCenter.class);
    when(dest.getDataCenter()).thenReturn(dc);
    final HostVO brocadeHost = mock(HostVO.class);
    when(hostdao.findById(anyLong())).thenReturn(brocadeHost);
    when(brocadeHost.getId()).thenReturn(NETWORK_ID);
    when(netmodel.findPhysicalNetworkId(anyLong(), (String) any(), (TrafficType) any())).thenReturn(NETWORK_ID);
    final BrocadeVcsDeviceVO brocadeDevice = mock(BrocadeVcsDeviceVO.class);
    when(brocadeDevice.getHostId()).thenReturn(NETWORK_ID);
    List<BrocadeVcsDeviceVO> devices = new ArrayList();
    devices.add(brocadeDevice);
    when(vcsdao.listByPhysicalNetwork(anyLong())).thenReturn(devices);
    final Domain dom = mock(Domain.class);
    when(dom.getName()).thenReturn("domain");
    final Account acc = mock(Account.class);
    when(acc.getAccountName()).thenReturn("accountname");
    final ReservationContext res = mock(ReservationContext.class);
    when(res.getDomain()).thenReturn(dom);
    when(res.getAccount()).thenReturn(acc);
    when(guestGuru.implement(network, offering, dest, res)).thenReturn(network);
    final CreateNetworkAnswer answer = mock(CreateNetworkAnswer.class);
    when(answer.getResult()).thenReturn(true);
    when(agentmgr.easySend(eq(NETWORK_ID), (Command) any())).thenReturn(answer);
    final Network implementednetwork = guru.implement(network, offering, dest, res);
    assertTrue(implementednetwork != null);
    verify(agentmgr, times(1)).easySend(eq(NETWORK_ID), (Command) any());
}
Also used : Account(com.cloud.user.Account) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NetworkVO(com.cloud.network.dao.NetworkVO) NetworkOffering(com.cloud.offering.NetworkOffering) ArrayList(java.util.ArrayList) URI(java.net.URI) HostVO(com.cloud.host.HostVO) BrocadeVcsDeviceVO(com.cloud.network.BrocadeVcsDeviceVO) ReservationContext(com.cloud.vm.ReservationContext) DataCenter(com.cloud.dc.DataCenter) DeployDestination(com.cloud.deploy.DeployDestination) CreateNetworkAnswer(com.cloud.agent.api.CreateNetworkAnswer) Network(com.cloud.network.Network) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) Domain(com.cloud.domain.Domain) Test(org.junit.Test)

Example 44 with DeployDestination

use of com.cloud.deploy.DeployDestination in project cloudstack by apache.

the class BrocadeVcsGuestNetworkGuruTest method testReserveFail.

@Test
public void testReserveFail() throws InsufficientVirtualNetworkCapacityException, URISyntaxException, InsufficientAddressCapacityException {
    final NetworkVO network = mock(NetworkVO.class);
    when(network.getName()).thenReturn("testnetwork");
    when(network.getState()).thenReturn(State.Implementing);
    when(network.getPhysicalNetworkId()).thenReturn(NETWORK_ID);
    when(network.getBroadcastUri()).thenReturn(new URI("vlan://14"));
    when(network.getDataCenterId()).thenReturn(NETWORK_ID);
    final NicProfile nic = mock(NicProfile.class);
    when(nic.getMacAddress()).thenReturn("macaddress");
    when(nic.getReservationStrategy()).thenReturn(ReservationStrategy.Start);
    final VirtualMachineProfile vmProfile = mock(VirtualMachineProfile.class);
    final DeployDestination dest = mock(DeployDestination.class);
    final DataCenterVO dc = mock(DataCenterVO.class);
    when(dest.getDataCenter()).thenReturn(dc);
    when(dcdao.findById((long) anyInt())).thenReturn(dc);
    final HostVO brocadeHost = mock(HostVO.class);
    when(hostdao.findById(anyLong())).thenReturn(brocadeHost);
    when(brocadeHost.getId()).thenReturn(NETWORK_ID);
    when(netmodel.findPhysicalNetworkId(anyLong(), (String) any(), (TrafficType) any())).thenReturn(NETWORK_ID);
    final BrocadeVcsDeviceVO brocadeDevice = mock(BrocadeVcsDeviceVO.class);
    when(brocadeDevice.getHostId()).thenReturn(NETWORK_ID);
    final List<BrocadeVcsDeviceVO> devices = mock(List.class);
    when(devices.isEmpty()).thenReturn(true);
    when(vcsdao.listByPhysicalNetwork(anyLong())).thenReturn(devices);
    final Domain dom = mock(Domain.class);
    when(dom.getName()).thenReturn("domain");
    final Account acc = mock(Account.class);
    when(acc.getAccountName()).thenReturn("accountname");
    final ReservationContext res = mock(ReservationContext.class);
    when(res.getDomain()).thenReturn(dom);
    when(res.getAccount()).thenReturn(acc);
    final AssociateMacToNetworkAnswer answer = mock(AssociateMacToNetworkAnswer.class);
    when(answer.getResult()).thenReturn(true);
    when(agentmgr.easySend(eq(NETWORK_ID), (Command) any())).thenReturn(answer);
    guru.reserve(nic, network, vmProfile, dest, res);
    verify(agentmgr, times(0)).easySend(eq(NETWORK_ID), (Command) any());
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) Account(com.cloud.user.Account) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NetworkVO(com.cloud.network.dao.NetworkVO) NicProfile(com.cloud.vm.NicProfile) URI(java.net.URI) HostVO(com.cloud.host.HostVO) BrocadeVcsDeviceVO(com.cloud.network.BrocadeVcsDeviceVO) ReservationContext(com.cloud.vm.ReservationContext) AssociateMacToNetworkAnswer(com.cloud.agent.api.AssociateMacToNetworkAnswer) DeployDestination(com.cloud.deploy.DeployDestination) VirtualMachineProfile(com.cloud.vm.VirtualMachineProfile) Domain(com.cloud.domain.Domain) Test(org.junit.Test)

Example 45 with DeployDestination

use of com.cloud.deploy.DeployDestination in project cloudstack by apache.

the class RouterDeploymentDefinitionTest method testFindDestinations.

@Test
public void testFindDestinations() {
    // Prepare
    when(mockDataCenter.getNetworkType()).thenReturn(NetworkType.Basic);
    when(mockDestination.getPod()).thenReturn(null);
    // Stub local method listByDataCenterIdVMTypeAndStates
    mockPods.add(mockHostPodVO1);
    mockPods.add(mockHostPodVO2);
    mockPods.add(mockHostPodVO3);
    final RouterDeploymentDefinition deployment = spy(this.deployment);
    doReturn(mockPods).when(deployment).listByDataCenterIdVMTypeAndStates(DATA_CENTER_ID, VirtualMachine.Type.User, VirtualMachine.State.Starting, VirtualMachine.State.Running);
    // Leave this one empty to force adding add destination for this pod
    final List<DomainRouterVO> virtualRouters1 = new ArrayList<>();
    when(mockRouterDao.listByPodIdAndStates(POD_ID1, VirtualMachine.State.Starting, VirtualMachine.State.Running)).thenReturn(virtualRouters1);
    // This list is not empty, so it will not add any for this pod, and continue with next pod
    final List<DomainRouterVO> virtualRouters2 = new ArrayList<>();
    final DomainRouterVO domainRouterVO1 = mock(DomainRouterVO.class);
    virtualRouters2.add(domainRouterVO1);
    when(mockRouterDao.listByPodIdAndStates(POD_ID2, VirtualMachine.State.Starting, VirtualMachine.State.Running)).thenReturn(virtualRouters2);
    // Leave this last one empty to check we finally added more than one afterwards
    final List<DomainRouterVO> virtualRouters3 = new ArrayList<>();
    when(mockRouterDao.listByPodIdAndStates(POD_ID3, VirtualMachine.State.Starting, VirtualMachine.State.Running)).thenReturn(virtualRouters3);
    // Execute
    final List<DeployDestination> destinations = deployment.findDestinations();
    // Assert that 2 were added (for the 1st and 3rd
    assertEquals("", 2, destinations.size());
    assertEquals("", mockDataCenter, destinations.get(0).getDataCenter());
    assertEquals("", mockHostPodVO1, destinations.get(0).getPod());
    assertEquals("", mockDataCenter, destinations.get(1).getDataCenter());
    assertEquals("", mockHostPodVO3, destinations.get(1).getPod());
}
Also used : DeployDestination(com.cloud.deploy.DeployDestination) ArrayList(java.util.ArrayList) DomainRouterVO(com.cloud.vm.DomainRouterVO) Test(org.junit.Test)

Aggregations

DeployDestination (com.cloud.deploy.DeployDestination)56 DataCenter (com.cloud.dc.DataCenter)27 Account (com.cloud.user.Account)27 Test (org.junit.Test)27 ReservationContext (com.cloud.vm.ReservationContext)26 HostVO (com.cloud.host.HostVO)19 Network (com.cloud.network.Network)18 NetworkVO (com.cloud.network.dao.NetworkVO)18 NetworkOffering (com.cloud.offering.NetworkOffering)18 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)18 Domain (com.cloud.domain.Domain)17 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)15 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)15 URI (java.net.URI)13 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)12 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)11 ArrayList (java.util.ArrayList)11 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)8 Host (com.cloud.host.Host)8 NiciraNvpDeviceVO (com.cloud.network.NiciraNvpDeviceVO)8