Search in sources :

Example 41 with DomainRouterVO

use of com.cloud.vm.DomainRouterVO in project cloudstack by apache.

the class InternalLoadBalancerVMManagerImpl method getDeploymentPlanAndInternalLbVms.

protected Pair<DeploymentPlan, List<DomainRouterVO>> getDeploymentPlanAndInternalLbVms(final DeployDestination dest, final long guestNetworkId, final Ip requestedGuestIp) {
    final long dcId = dest.getDataCenter().getId();
    final DeploymentPlan plan = new DataCenterDeployment(dcId);
    final List<DomainRouterVO> internalLbVms = findInternalLbVms(guestNetworkId, requestedGuestIp);
    return new Pair<DeploymentPlan, List<DomainRouterVO>>(plan, internalLbVms);
}
Also used : DataCenterDeployment(com.cloud.deploy.DataCenterDeployment) DeploymentPlan(com.cloud.deploy.DeploymentPlan) DomainRouterVO(com.cloud.vm.DomainRouterVO) Pair(com.cloud.utils.Pair)

Example 42 with DomainRouterVO

use of com.cloud.vm.DomainRouterVO in project cloudstack by apache.

the class InternalLoadBalancerVMManagerImpl method deployInternalLbVm.

protected DomainRouterVO deployInternalLbVm(final Account owner, final DeployDestination dest, final DeploymentPlan plan, final Map<Param, Object> params, final long internalLbProviderId, final long svcOffId, final Long vpcId, final LinkedHashMap<Network, List<? extends NicProfile>> networks, final boolean startVm) throws ConcurrentOperationException, InsufficientAddressCapacityException, InsufficientServerCapacityException, InsufficientCapacityException, StorageUnavailableException, ResourceUnavailableException {
    final ServiceOfferingVO routerOffering = _serviceOfferingDao.findById(svcOffId);
    // Internal lb is the network element, we don't know the hypervisor type yet.
    // Try to allocate the internal lb twice using diff hypervisors, and when failed both times, throw the exception up
    final List<HypervisorType> hypervisors = getHypervisors(dest, plan, null);
    int allocateRetry = 0;
    int startRetry = 0;
    DomainRouterVO internalLbVm = null;
    for (final Iterator<HypervisorType> iter = hypervisors.iterator(); iter.hasNext(); ) {
        final HypervisorType hType = iter.next();
        try {
            final long id = _internalLbVmDao.getNextInSequence(Long.class, "id");
            if (s_logger.isDebugEnabled()) {
                s_logger.debug("Creating the internal lb vm " + id + " in datacenter " + dest.getDataCenter() + " with hypervisor type " + hType);
            }
            String templateName = null;
            switch(hType) {
                case XenServer:
                    templateName = VirtualNetworkApplianceManager.RouterTemplateXen.valueIn(dest.getDataCenter().getId());
                    break;
                case KVM:
                    templateName = VirtualNetworkApplianceManager.RouterTemplateKvm.valueIn(dest.getDataCenter().getId());
                    break;
                case VMware:
                    templateName = VirtualNetworkApplianceManager.RouterTemplateVmware.valueIn(dest.getDataCenter().getId());
                    break;
                case Hyperv:
                    templateName = VirtualNetworkApplianceManager.RouterTemplateHyperV.valueIn(dest.getDataCenter().getId());
                    break;
                case LXC:
                    templateName = VirtualNetworkApplianceManager.RouterTemplateLxc.valueIn(dest.getDataCenter().getId());
                    break;
                default:
                    break;
            }
            final VMTemplateVO template = _templateDao.findRoutingTemplate(hType, templateName);
            if (template == null) {
                s_logger.debug(hType + " won't support system vm, skip it");
                continue;
            }
            long userId = CallContext.current().getCallingUserId();
            if (CallContext.current().getCallingAccount().getId() != owner.getId()) {
                List<UserVO> userVOs = _userDao.listByAccount(owner.getAccountId());
                if (!userVOs.isEmpty()) {
                    userId = userVOs.get(0).getId();
                }
            }
            internalLbVm = new DomainRouterVO(id, routerOffering.getId(), internalLbProviderId, VirtualMachineName.getSystemVmName(id, _instance, InternalLbVmNamePrefix), template.getId(), template.getHypervisorType(), template.getGuestOSId(), owner.getDomainId(), owner.getId(), userId, false, RedundantState.UNKNOWN, false, false, VirtualMachine.Type.InternalLoadBalancerVm, vpcId);
            internalLbVm.setRole(Role.INTERNAL_LB_VM);
            internalLbVm = _internalLbVmDao.persist(internalLbVm);
            _itMgr.allocate(internalLbVm.getInstanceName(), template, routerOffering, networks, plan, null);
            internalLbVm = _internalLbVmDao.findById(internalLbVm.getId());
        } catch (final InsufficientCapacityException ex) {
            if (allocateRetry < 2 && iter.hasNext()) {
                s_logger.debug("Failed to allocate the Internal lb vm with hypervisor type " + hType + ", retrying one more time");
                continue;
            } else {
                throw ex;
            }
        } finally {
            allocateRetry++;
        }
        if (startVm) {
            try {
                internalLbVm = startInternalLbVm(internalLbVm, _accountMgr.getSystemAccount(), User.UID_SYSTEM, params);
                break;
            } catch (final InsufficientCapacityException ex) {
                if (startRetry < 2 && iter.hasNext()) {
                    s_logger.debug("Failed to start the Internal lb vm  " + internalLbVm + " with hypervisor type " + hType + ", " + "destroying it and recreating one more time");
                    // destroy the internal lb vm
                    destroyInternalLbVm(internalLbVm.getId(), _accountMgr.getSystemAccount(), User.UID_SYSTEM);
                    continue;
                } else {
                    throw ex;
                }
            } finally {
                startRetry++;
            }
        } else {
            // return stopped internal lb vm
            return internalLbVm;
        }
    }
    return internalLbVm;
}
Also used : HypervisorType(com.cloud.hypervisor.Hypervisor.HypervisorType) UserVO(com.cloud.user.UserVO) VMTemplateVO(com.cloud.storage.VMTemplateVO) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) ServiceOfferingVO(com.cloud.service.ServiceOfferingVO) DomainRouterVO(com.cloud.vm.DomainRouterVO)

Example 43 with DomainRouterVO

use of com.cloud.vm.DomainRouterVO in project cloudstack by apache.

the class InternalLoadBalancerVMManagerImpl method destroyInternalLbVm.

@Override
public boolean destroyInternalLbVm(final long vmId, final Account caller, final Long callerUserId) throws ResourceUnavailableException, ConcurrentOperationException {
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("Attempting to destroy Internal LB vm " + vmId);
    }
    final DomainRouterVO internalLbVm = _internalLbVmDao.findById(vmId);
    if (internalLbVm == null) {
        return true;
    }
    _accountMgr.checkAccess(caller, null, true, internalLbVm);
    _itMgr.expunge(internalLbVm.getUuid());
    _internalLbVmDao.remove(internalLbVm.getId());
    return true;
}
Also used : DomainRouterVO(com.cloud.vm.DomainRouterVO)

Example 44 with DomainRouterVO

use of com.cloud.vm.DomainRouterVO in project cloudstack by apache.

the class InternalLoadBalancerVMManagerImpl method getInternalLbControlIp.

protected String getInternalLbControlIp(final long internalLbVmId) {
    String controlIpAddress = null;
    final List<NicVO> nics = _nicDao.listByVmId(internalLbVmId);
    for (final NicVO nic : nics) {
        final Network ntwk = _ntwkModel.getNetwork(nic.getNetworkId());
        if (ntwk.getTrafficType() == TrafficType.Control) {
            controlIpAddress = nic.getIPv4Address();
        }
    }
    if (controlIpAddress == null) {
        s_logger.warn("Unable to find Internal LB control ip in its attached NICs!. Internal LB vm: " + internalLbVmId);
        final DomainRouterVO internalLbVm = _internalLbVmDao.findById(internalLbVmId);
        return internalLbVm.getPrivateIpAddress();
    }
    return controlIpAddress;
}
Also used : Network(com.cloud.network.Network) NicVO(com.cloud.vm.NicVO) DomainRouterVO(com.cloud.vm.DomainRouterVO)

Example 45 with DomainRouterVO

use of com.cloud.vm.DomainRouterVO in project cloudstack by apache.

the class InternalLBVMManagerTest method setUp.

@Override
@Before
public void setUp() {
    // mock system offering creation as it's used by configure() method called by initComponentsLifeCycle
    Mockito.when(_accountMgr.getAccount(1L)).thenReturn(new AccountVO());
    ServiceOfferingVO off = new ServiceOfferingVO("alena", 1, 1, 1, 1, 1, false, "alena", false, VirtualMachine.Type.InternalLoadBalancerVm, false);
    off = setId(off, 1);
    List<ServiceOfferingVO> list = new ArrayList<ServiceOfferingVO>();
    list.add(off);
    list.add(off);
    Mockito.when(_svcOffDao.createSystemServiceOfferings(nullable(String.class), nullable(String.class), nullable(Integer.class), nullable(Integer.class), nullable(Integer.class), nullable(Integer.class), nullable(Integer.class), nullable(Boolean.class), nullable(String.class), nullable(ProvisioningType.class), nullable(Boolean.class), nullable(String.class), nullable(Boolean.class), nullable(VirtualMachine.Type.class), nullable(Boolean.class))).thenReturn(list);
    ComponentContext.initComponentsLifeCycle();
    vm = new DomainRouterVO(1L, off.getId(), 1, "alena", 1, HypervisorType.XenServer, 1, 1, 1, 1, false, null, false, false, VirtualMachine.Type.InternalLoadBalancerVm, null);
    vm.setRole(Role.INTERNAL_LB_VM);
    vm = setId(vm, 1);
    vm.setPrivateIpAddress("10.2.2.2");
    final NicVO nic = new NicVO("somereserver", 1L, 1L, VirtualMachine.Type.InternalLoadBalancerVm);
    nic.setIPv4Address(requestedIp);
    final List<DomainRouterVO> emptyList = new ArrayList<DomainRouterVO>();
    final List<DomainRouterVO> nonEmptyList = new ArrayList<DomainRouterVO>();
    nonEmptyList.add(vm);
    Mockito.when(_domainRouterDao.listByNetworkAndRole(invalidNtwkId, Role.INTERNAL_LB_VM)).thenReturn(emptyList);
    Mockito.when(_domainRouterDao.listByNetworkAndRole(validNtwkId, Role.INTERNAL_LB_VM)).thenReturn(nonEmptyList);
    Mockito.when(_nicDao.findByNtwkIdAndInstanceId(validNtwkId, 1)).thenReturn(nic);
    Mockito.when(_nicDao.findByNtwkIdAndInstanceId(invalidNtwkId, 1)).thenReturn(nic);
    final Answer answer = new Answer(null, true, null);
    final Answer[] answers = new Answer[1];
    answers[0] = answer;
    try {
        Mockito.when(_agentMgr.send(nullable(Long.class), nullable(Commands.class))).thenReturn(answers);
    } catch (final AgentUnavailableException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (final OperationTimedoutException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    createNetwork();
    Mockito.when(_ntwkModel.getNetwork(Matchers.anyLong())).thenReturn(ntwk);
    Mockito.when(_itMgr.toNicTO(Matchers.any(NicProfile.class), Matchers.any(HypervisorType.class))).thenReturn(null);
    Mockito.when(_domainRouterDao.findById(Matchers.anyLong())).thenReturn(vm);
    final DataCenterVO dc = new DataCenterVO(1L, null, null, null, null, null, null, null, null, null, NetworkType.Advanced, null, null);
    Mockito.when(_dcDao.findById(Matchers.anyLong())).thenReturn(dc);
    final NetworkOfferingVO networkOfferingVO = new NetworkOfferingVO();
    networkOfferingVO.setConcurrentConnections(500);
    Mockito.when(_offeringDao.findById(Matchers.anyLong())).thenReturn(networkOfferingVO);
    Mockito.when(_domainRouterDao.findById(validVmId)).thenReturn(vm);
    Mockito.when(_domainRouterDao.findById(invalidVmId)).thenReturn(null);
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) OperationTimedoutException(com.cloud.exception.OperationTimedoutException) ArrayList(java.util.ArrayList) NicProfile(com.cloud.vm.NicProfile) AccountVO(com.cloud.user.AccountVO) ServiceOfferingVO(com.cloud.service.ServiceOfferingVO) HypervisorType(com.cloud.hypervisor.Hypervisor.HypervisorType) ProvisioningType(com.cloud.storage.Storage.ProvisioningType) Answer(com.cloud.agent.api.Answer) NetworkType(com.cloud.dc.DataCenter.NetworkType) HypervisorType(com.cloud.hypervisor.Hypervisor.HypervisorType) ProvisioningType(com.cloud.storage.Storage.ProvisioningType) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) Commands(com.cloud.agent.manager.Commands) NetworkOfferingVO(com.cloud.offerings.NetworkOfferingVO) NicVO(com.cloud.vm.NicVO) DomainRouterVO(com.cloud.vm.DomainRouterVO) Before(org.junit.Before)

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