Search in sources :

Example 1 with DomainRouterVO

use of com.cloud.vm.DomainRouterVO in project CloudStack-archive by CloudStack-extras.

the class ElbVmMapDaoTest method testFindUnused.

public void testFindUnused() {
    ElasticLbVmMapDaoImpl dao = ComponentLocator.inject(ElasticLbVmMapDaoImpl.class);
    List<DomainRouterVO> map = dao.listUnusedElbVms();
    if (map == null) {
        System.out.println("Not Found");
    } else {
        System.out.println("Found");
    }
}
Also used : ElasticLbVmMapDaoImpl(com.cloud.network.lb.dao.ElasticLbVmMapDaoImpl) DomainRouterVO(com.cloud.vm.DomainRouterVO)

Example 2 with DomainRouterVO

use of com.cloud.vm.DomainRouterVO in project cosmic by MissionCriticalCloud.

the class VpcVirtualRouterElementTest method testApplyVpnUsers.

@Test
public void testApplyVpnUsers() {
    vpcVirtualRouterElement._vpcRouterMgr = _vpcRouterMgr;
    final AdvancedNetworkTopology advancedNetworkTopology = Mockito.mock(AdvancedNetworkTopology.class);
    final BasicNetworkTopology basicNetworkTopology = Mockito.mock(BasicNetworkTopology.class);
    networkTopologyContext.setAdvancedNetworkTopology(advancedNetworkTopology);
    networkTopologyContext.setBasicNetworkTopology(basicNetworkTopology);
    networkTopologyContext.init();
    final Vpc vpc = Mockito.mock(Vpc.class);
    final Zone zone = Mockito.mock(Zone.class);
    final RemoteAccessVpn remoteAccessVpn = Mockito.mock(RemoteAccessVpn.class);
    final DomainRouterVO domainRouterVO1 = Mockito.mock(DomainRouterVO.class);
    final DomainRouterVO domainRouterVO2 = Mockito.mock(DomainRouterVO.class);
    final VpnUser vpnUser1 = Mockito.mock(VpnUser.class);
    final VpnUser vpnUser2 = Mockito.mock(VpnUser.class);
    final List<VpnUser> users = new ArrayList<>();
    users.add(vpnUser1);
    users.add(vpnUser2);
    final List<DomainRouterVO> routers = new ArrayList<>();
    routers.add(domainRouterVO1);
    routers.add(domainRouterVO2);
    final Long vpcId = new Long(1l);
    final Long zoneId = new Long(1l);
    when(remoteAccessVpn.getVpcId()).thenReturn(vpcId);
    when(_vpcRouterMgr.getVpcRouters(vpcId)).thenReturn(routers);
    when(_entityMgr.findById(Vpc.class, vpcId)).thenReturn(vpc);
    when(vpc.getZoneId()).thenReturn(zoneId);
    when(zoneRepository.findOne(zoneId)).thenReturn(zone);
    when(networkTopologyContext.retrieveNetworkTopology(zone)).thenReturn(advancedNetworkTopology);
    try {
        when(advancedNetworkTopology.applyVpnUsers(remoteAccessVpn, users, domainRouterVO1)).thenReturn(new String[] { "user1", "user2" });
        when(advancedNetworkTopology.applyVpnUsers(remoteAccessVpn, users, domainRouterVO2)).thenReturn(new String[] { "user3", "user4" });
    } catch (final ResourceUnavailableException e) {
        fail(e.getMessage());
    }
    try {
        final String[] results = vpcVirtualRouterElement.applyVpnUsers(remoteAccessVpn, users);
        assertNotNull(results);
        assertEquals(results[0], "user1");
        assertEquals(results[1], "user2");
        assertEquals(results[2], "user3");
        assertEquals(results[3], "user4");
    } catch (final ResourceUnavailableException e) {
        fail(e.getMessage());
    }
    verify(remoteAccessVpn, times(1)).getVpcId();
    verify(vpc, times(1)).getZoneId();
    verify(zoneRepository, times(1)).findOne(zoneId);
    verify(networkTopologyContext, times(1)).retrieveNetworkTopology(zone);
}
Also used : BasicNetworkTopology(com.cloud.network.topology.BasicNetworkTopology) Zone(com.cloud.db.model.Zone) Vpc(com.cloud.network.vpc.Vpc) ArrayList(java.util.ArrayList) AdvancedNetworkTopology(com.cloud.network.topology.AdvancedNetworkTopology) VpnUser(com.cloud.network.VpnUser) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) RemoteAccessVpn(com.cloud.network.RemoteAccessVpn) DomainRouterVO(com.cloud.vm.DomainRouterVO) Test(org.junit.Test)

Example 3 with DomainRouterVO

use of com.cloud.vm.DomainRouterVO in project cosmic by MissionCriticalCloud.

the class StoragePoolAutomationImpl method cancelMaintain.

@Override
public boolean cancelMaintain(final DataStore store) {
    // Change the storage state back to up
    final Long userId = CallContext.current().getCallingUserId();
    final User user = _userDao.findById(userId);
    final Account account = CallContext.current().getCallingAccount();
    final StoragePoolVO poolVO = primaryDataStoreDao.findById(store.getId());
    final StoragePool pool = (StoragePool) store;
    // Handeling the Zone wide and cluster wide primay storage
    List<HostVO> hosts = new ArrayList<>();
    // if the storage scope is ZONE wide, then get all the hosts for which hypervisor ZWSP created to send Modifystoragepoolcommand
    if (poolVO.getScope().equals(ScopeType.ZONE)) {
        if (HypervisorType.Any.equals(pool.getHypervisor())) {
            hosts = _resourceMgr.listAllUpAndEnabledHostsInOneZone(pool.getDataCenterId());
        } else {
            hosts = _resourceMgr.listAllUpAndEnabledHostsInOneZoneByHypervisor(poolVO.getHypervisor(), pool.getDataCenterId());
        }
    } else {
        hosts = _resourceMgr.listHostsInClusterByStatus(pool.getClusterId(), Status.Up);
    }
    if (hosts == null || hosts.size() == 0) {
        return true;
    }
    // add heartbeat
    for (final HostVO host : hosts) {
        final ModifyStoragePoolCommand msPoolCmd = new ModifyStoragePoolCommand(true, pool);
        final Answer answer = agentMgr.easySend(host.getId(), msPoolCmd);
        if (answer == null || !answer.getResult()) {
            if (s_logger.isDebugEnabled()) {
                s_logger.debug("ModifyStoragePool add failed due to " + ((answer == null) ? "answer null" : answer.getDetails()));
            }
        } else {
            if (s_logger.isDebugEnabled()) {
                s_logger.debug("ModifyStoragePool add secceeded");
            }
        }
    }
    // 2. Get a list of pending work for this queue
    final List<StoragePoolWorkVO> pendingWork = _storagePoolWorkDao.listPendingWorkForCancelMaintenanceByPoolId(poolVO.getId());
    // 3. work through the queue
    for (final StoragePoolWorkVO work : pendingWork) {
        try {
            final VMInstanceVO vmInstance = vmDao.findById(work.getVmId());
            if (vmInstance == null) {
                continue;
            }
            // proxy
            if (vmInstance.getType().equals(VirtualMachine.Type.ConsoleProxy)) {
                final ConsoleProxyVO consoleProxy = _consoleProxyDao.findById(vmInstance.getId());
                vmMgr.advanceStart(consoleProxy.getUuid(), null, null);
                // update work queue
                work.setStartedAfterMaintenance(true);
                _storagePoolWorkDao.update(work.getId(), work);
            }
            // if the instance is of type ssvm, call the ssvm manager
            if (vmInstance.getType().equals(VirtualMachine.Type.SecondaryStorageVm)) {
                final SecondaryStorageVmVO ssVm = _secStrgDao.findById(vmInstance.getId());
                vmMgr.advanceStart(ssVm.getUuid(), null, null);
                // update work queue
                work.setStartedAfterMaintenance(true);
                _storagePoolWorkDao.update(work.getId(), work);
            }
            // manager
            if (vmInstance.getType().equals(VirtualMachine.Type.DomainRouter)) {
                final DomainRouterVO domR = _domrDao.findById(vmInstance.getId());
                vmMgr.advanceStart(domR.getUuid(), null, null);
                // update work queue
                work.setStartedAfterMaintenance(true);
                _storagePoolWorkDao.update(work.getId(), work);
            }
            // if the instance is of type user vm, call the user vm manager
            if (vmInstance.getType().equals(VirtualMachine.Type.User)) {
                // don't allow to start vm that doesn't have a root volume
                if (volumeDao.findByInstanceAndType(vmInstance.getId(), Volume.Type.ROOT).isEmpty()) {
                    _storagePoolWorkDao.remove(work.getId());
                } else {
                    final UserVmVO userVm = userVmDao.findById(vmInstance.getId());
                    vmMgr.advanceStart(userVm.getUuid(), null, null);
                    work.setStartedAfterMaintenance(true);
                    _storagePoolWorkDao.update(work.getId(), work);
                }
            }
        } catch (final Exception e) {
            s_logger.debug("Failed start vm", e);
            throw new CloudRuntimeException(e.toString());
        }
    }
    return false;
}
Also used : Account(com.cloud.user.Account) SecondaryStorageVmVO(com.cloud.vm.SecondaryStorageVmVO) UserVmVO(com.cloud.vm.UserVmVO) User(com.cloud.user.User) ArrayList(java.util.ArrayList) VMInstanceVO(com.cloud.vm.VMInstanceVO) HostVO(com.cloud.host.HostVO) ModifyStoragePoolCommand(com.cloud.agent.api.ModifyStoragePoolCommand) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) Answer(com.cloud.agent.api.Answer) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) StoragePoolVO(com.cloud.storage.datastore.db.StoragePoolVO) ConsoleProxyVO(com.cloud.vm.ConsoleProxyVO) DomainRouterVO(com.cloud.vm.DomainRouterVO)

Example 4 with DomainRouterVO

use of com.cloud.vm.DomainRouterVO in project cosmic by MissionCriticalCloud.

the class RouterControlHelperTest method testGetRouterControlIpWithRouterIp.

@Test
public void testGetRouterControlIpWithRouterIp() {
    // Prepare
    final List<NicVO> nics = new ArrayList<>();
    final NicVO nic1 = mock(NicVO.class);
    when(nic1.getNetworkId()).thenReturn(NW_ID_1);
    when(nic1.getIPv4Address()).thenReturn(null);
    nics.add(nic1);
    when(this.nicDao.listByVmId(ROUTER_ID)).thenReturn(nics);
    final NetworkVO nw1 = mock(NetworkVO.class);
    when(nw1.getTrafficType()).thenReturn(TrafficType.Public);
    when(this.nwDao.findById(NW_ID_1)).thenReturn(nw1);
    final DomainRouterVO router = mock(DomainRouterVO.class);
    when(this.routerDao.findById(ROUTER_ID)).thenReturn(router);
    when(router.getPrivateIpAddress()).thenReturn(IP4_ADDRES1);
    // Execute
    final String ip4address = this.routerControlHelper.getRouterControlIp(ROUTER_ID);
    // Assert
    assertEquals(DIDN_T_GET_THE_EXPECTED_IP4_ADDRESS, IP4_ADDRES1, ip4address);
}
Also used : NetworkVO(com.cloud.network.dao.NetworkVO) ArrayList(java.util.ArrayList) NicVO(com.cloud.vm.NicVO) DomainRouterVO(com.cloud.vm.DomainRouterVO) Test(org.junit.Test)

Example 5 with DomainRouterVO

use of com.cloud.vm.DomainRouterVO in project cosmic by MissionCriticalCloud.

the class RouterDeploymentDefinitionTest method testDeployAllVirtualRouters.

@Test
public void testDeployAllVirtualRouters() throws ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException {
    // Prepare
    deployment.routers = new ArrayList<>();
    when(mockNw.isRedundant()).thenReturn(true);
    // this.deployment.routers.add(routerVO1);
    final RouterDeploymentDefinition deploymentUT = Mockito.spy(deployment);
    doReturn(2).when(deploymentUT).getNumberOfRoutersToDeploy();
    final DomainRouterVO routerVO1 = mock(DomainRouterVO.class);
    final DomainRouterVO routerVO2 = mock(DomainRouterVO.class);
    when(mockNetworkHelper.deployRouter(deploymentUT, false)).thenReturn(routerVO1).thenReturn(routerVO2);
    // Execute
    deploymentUT.deployAllVirtualRouters();
    // Assert
    verify(mockRouterDao, times(1)).addRouterToGuestNetwork(routerVO1, mockNw);
    verify(mockRouterDao, times(1)).addRouterToGuestNetwork(routerVO2, mockNw);
    assertEquals("First router to deploy was not added to list of available routers", routerVO1, deployment.routers.get(0));
    assertEquals("Second router to deploy was not added to list of available routers", routerVO2, deployment.routers.get(1));
}
Also used : DomainRouterVO(com.cloud.vm.DomainRouterVO) Test(org.junit.Test)

Aggregations

DomainRouterVO (com.cloud.vm.DomainRouterVO)253 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)64 ArrayList (java.util.ArrayList)60 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)47 DataCenterVO (com.cloud.dc.DataCenterVO)36 Network (com.cloud.network.Network)34 Test (org.junit.Test)32 NicProfile (com.cloud.vm.NicProfile)29 NetworkTopology (org.apache.cloudstack.network.topology.NetworkTopology)28 Zone (com.cloud.db.model.Zone)27 Account (com.cloud.user.Account)27 NetworkTopology (com.cloud.network.topology.NetworkTopology)23 Vpc (com.cloud.network.vpc.Vpc)22 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)20 VirtualMachineProfile (com.cloud.vm.VirtualMachineProfile)17 HashMap (java.util.HashMap)17 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)16 NetworkVO (com.cloud.network.dao.NetworkVO)16 UserVmVO (com.cloud.vm.UserVmVO)15 Answer (com.cloud.agent.api.Answer)14