Search in sources :

Example 6 with LbHealthCheckPolicy

use of com.cloud.network.lb.LoadBalancingRule.LbHealthCheckPolicy in project cloudstack by apache.

the class LoadBalancingRulesManagerImpl method getHealthCheckPolicies.

@Override
public List<LbHealthCheckPolicy> getHealthCheckPolicies(long lbId) {
    List<LbHealthCheckPolicy> healthCheckPolicies = new ArrayList<LbHealthCheckPolicy>();
    List<LBHealthCheckPolicyVO> hcDbpolicies = _lb2healthcheckDao.listByLoadBalancerIdAndDisplayFlag(lbId, null);
    for (LBHealthCheckPolicyVO policy : hcDbpolicies) {
        String pingpath = policy.getpingpath();
        LbHealthCheckPolicy hDbPolicy = new LbHealthCheckPolicy(pingpath, policy.getDescription(), policy.getResponseTime(), policy.getHealthcheckInterval(), policy.getHealthcheckThresshold(), policy.getUnhealthThresshold(), policy.isRevoke());
        healthCheckPolicies.add(hDbPolicy);
    }
    return healthCheckPolicies;
}
Also used : ArrayList(java.util.ArrayList) LbHealthCheckPolicy(com.cloud.network.lb.LoadBalancingRule.LbHealthCheckPolicy) LBHealthCheckPolicyVO(com.cloud.network.LBHealthCheckPolicyVO)

Example 7 with LbHealthCheckPolicy

use of com.cloud.network.lb.LoadBalancingRule.LbHealthCheckPolicy in project cloudstack by apache.

the class LoadBalancingRulesManagerImpl method updateLBHealthChecks.

// This method will check the status of services which has monitors created
// by CloudStack and update them in lbvmmap table
@DB
@Override
public void updateLBHealthChecks(Scheme scheme) throws ResourceUnavailableException {
    List<LoadBalancerVO> rules = _lbDao.listAll();
    List<NetworkVO> networks = _networkDao.listAll();
    List<LoadBalancerTO> stateRules = null;
    boolean isHandled = false;
    for (NetworkVO ntwk : networks) {
        Network network = _networkDao.findById(ntwk.getId());
        String capability = getLBCapability(network.getId(), Capability.HealthCheckPolicy.getName());
        if (capability != null && capability.equalsIgnoreCase("true")) {
            /*
                 * s_logger.debug(
                 * "HealthCheck Manager :: LB Provider in the Network has the Healthcheck policy capability :: "
                 * + provider.get(0).getName());
                 */
            rules = _lbDao.listByNetworkIdAndScheme(network.getId(), scheme);
            if (rules != null && rules.size() > 0) {
                List<LoadBalancingRule> lbrules = new ArrayList<LoadBalancingRule>();
                for (LoadBalancerVO lb : rules) {
                    List<LbDestination> dstList = getExistingDestinations(lb.getId());
                    List<LbHealthCheckPolicy> hcPolicyList = getHealthCheckPolicies(lb.getId());
                    // hashealtChecks
                    if (hcPolicyList != null && hcPolicyList.size() > 0) {
                        Ip sourceIp = getSourceIp(lb);
                        LoadBalancingRule loadBalancing = new LoadBalancingRule(lb, dstList, null, hcPolicyList, sourceIp, null, lb.getLbProtocol());
                        lbrules.add(loadBalancing);
                    }
                }
                if (lbrules.size() > 0) {
                    isHandled = false;
                    for (LoadBalancingServiceProvider lbElement : _lbProviders) {
                        stateRules = lbElement.updateHealthChecks(network, lbrules);
                        if (stateRules != null && stateRules.size() > 0) {
                            for (LoadBalancerTO lbto : stateRules) {
                                LoadBalancerVO ulb = _lbDao.findByUuid(lbto.getUuid());
                                List<LoadBalancerVMMapVO> lbVmMaps = _lb2VmMapDao.listByLoadBalancerId(ulb.getId());
                                for (LoadBalancerVMMapVO lbVmMap : lbVmMaps) {
                                    UserVm vm = _vmDao.findById(lbVmMap.getInstanceId());
                                    Nic nic = _nicDao.findByInstanceIdAndNetworkIdIncludingRemoved(ulb.getNetworkId(), vm.getId());
                                    String dstIp = lbVmMap.getInstanceIp() == null ? nic.getIPv4Address() : lbVmMap.getInstanceIp();
                                    for (int i = 0; i < lbto.getDestinations().length; i++) {
                                        LoadBalancerTO.DestinationTO des = lbto.getDestinations()[i];
                                        if (dstIp.equalsIgnoreCase(lbto.getDestinations()[i].getDestIp())) {
                                            lbVmMap.setState(des.getMonitorState());
                                            _lb2VmMapDao.persist(lbVmMap);
                                            s_logger.debug("Updating the LB VM Map table with the service state");
                                        }
                                    }
                                }
                            }
                            isHandled = true;
                        }
                        if (isHandled) {
                            break;
                        }
                    }
                }
            }
        } else {
        // s_logger.debug("HealthCheck Manager :: LB Provider in the Network DNOT the Healthcheck policy capability ");
        }
    }
}
Also used : NetworkVO(com.cloud.network.dao.NetworkVO) Ip(com.cloud.utils.net.Ip) PublicIp(com.cloud.network.addr.PublicIp) LoadBalancerVO(com.cloud.network.dao.LoadBalancerVO) ArrayList(java.util.ArrayList) Nic(com.cloud.vm.Nic) LoadBalancerTO(com.cloud.agent.api.to.LoadBalancerTO) LoadBalancingServiceProvider(com.cloud.network.element.LoadBalancingServiceProvider) LbDestination(com.cloud.network.lb.LoadBalancingRule.LbDestination) UserVm(com.cloud.uservm.UserVm) Network(com.cloud.network.Network) LbHealthCheckPolicy(com.cloud.network.lb.LoadBalancingRule.LbHealthCheckPolicy) LoadBalancerVMMapVO(com.cloud.network.dao.LoadBalancerVMMapVO) DB(com.cloud.utils.db.DB)

Example 8 with LbHealthCheckPolicy

use of com.cloud.network.lb.LoadBalancingRule.LbHealthCheckPolicy in project cloudstack by apache.

the class LoadBalancingRulesManagerImpl method getLoadBalancerRuleToApply.

private LoadBalancingRule getLoadBalancerRuleToApply(LoadBalancerVO lb) {
    List<LbStickinessPolicy> policyList = getStickinessPolicies(lb.getId());
    Ip sourceIp = getSourceIp(lb);
    LbSslCert sslCert = getLbSslCert(lb.getId());
    LoadBalancingRule loadBalancing = new LoadBalancingRule(lb, null, policyList, null, sourceIp, sslCert, lb.getLbProtocol());
    if (_autoScaleVmGroupDao.isAutoScaleLoadBalancer(lb.getId())) {
        // Get the associated VmGroup
        AutoScaleVmGroupVO vmGroup = _autoScaleVmGroupDao.listByAll(lb.getId(), null).get(0);
        LbAutoScaleVmGroup lbAutoScaleVmGroup = getLbAutoScaleVmGroup(vmGroup, vmGroup.getState(), lb);
        loadBalancing.setAutoScaleVmGroup(lbAutoScaleVmGroup);
    } else {
        List<LbDestination> dstList = getExistingDestinations(lb.getId());
        loadBalancing.setDestinations(dstList);
        List<LbHealthCheckPolicy> hcPolicyList = getHealthCheckPolicies(lb.getId());
        loadBalancing.setHealthCheckPolicies(hcPolicyList);
    }
    return loadBalancing;
}
Also used : LbSslCert(com.cloud.network.lb.LoadBalancingRule.LbSslCert) AutoScaleVmGroupVO(com.cloud.network.as.AutoScaleVmGroupVO) Ip(com.cloud.utils.net.Ip) PublicIp(com.cloud.network.addr.PublicIp) LbHealthCheckPolicy(com.cloud.network.lb.LoadBalancingRule.LbHealthCheckPolicy) LbStickinessPolicy(com.cloud.network.lb.LoadBalancingRule.LbStickinessPolicy) LbAutoScaleVmGroup(com.cloud.network.lb.LoadBalancingRule.LbAutoScaleVmGroup) LbDestination(com.cloud.network.lb.LoadBalancingRule.LbDestination)

Example 9 with LbHealthCheckPolicy

use of com.cloud.network.lb.LoadBalancingRule.LbHealthCheckPolicy in project cloudstack by apache.

the class ApplicationLoadBalancerManagerImpl method createApplicationLoadBalancer.

protected ApplicationLoadBalancerRule createApplicationLoadBalancer(String name, String description, Scheme scheme, Network sourceIpNtwk, String sourceIp, int sourcePort, int instancePort, String algorithm, Account lbOwner, Network guestNtwk, Boolean forDisplay) throws NetworkRuleConflictException, InsufficientVirtualNetworkCapacityException {
    //Only Internal scheme is supported in this release
    if (scheme != Scheme.Internal) {
        throw new UnsupportedServiceException("Only scheme of type " + Scheme.Internal + " is supported");
    }
    //1) Validate LB rule's parameters
    validateLbRule(sourcePort, instancePort, algorithm, guestNtwk, scheme);
    //2) Validate source network
    validateSourceIpNtwkForLbRule(sourceIpNtwk, scheme);
    //3) Get source ip address
    Ip sourceIpAddr = getSourceIp(scheme, sourceIpNtwk, sourceIp);
    ApplicationLoadBalancerRuleVO newRule = new ApplicationLoadBalancerRuleVO(name, description, sourcePort, instancePort, algorithm, guestNtwk.getId(), lbOwner.getId(), lbOwner.getDomainId(), sourceIpAddr, sourceIpNtwk.getId(), scheme);
    if (forDisplay != null) {
        newRule.setDisplay(forDisplay);
    }
    //4) Validate Load Balancing rule on the providers
    LoadBalancingRule loadBalancing = new LoadBalancingRule(newRule, new ArrayList<LbDestination>(), new ArrayList<LbStickinessPolicy>(), new ArrayList<LbHealthCheckPolicy>(), sourceIpAddr, null, null);
    if (!_lbMgr.validateLbRule(loadBalancing)) {
        throw new InvalidParameterValueException("LB service provider cannot support this rule");
    }
    //5) Persist Load Balancer rule
    return persistLbRule(newRule);
}
Also used : ApplicationLoadBalancerRuleVO(org.apache.cloudstack.lb.ApplicationLoadBalancerRuleVO) LoadBalancingRule(com.cloud.network.lb.LoadBalancingRule) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) UnsupportedServiceException(com.cloud.exception.UnsupportedServiceException) Ip(com.cloud.utils.net.Ip) LbHealthCheckPolicy(com.cloud.network.lb.LoadBalancingRule.LbHealthCheckPolicy) LbStickinessPolicy(com.cloud.network.lb.LoadBalancingRule.LbStickinessPolicy) LbDestination(com.cloud.network.lb.LoadBalancingRule.LbDestination)

Example 10 with LbHealthCheckPolicy

use of com.cloud.network.lb.LoadBalancingRule.LbHealthCheckPolicy in project cloudstack by apache.

the class ElasticLoadBalancerManagerImpl method applyLoadBalancerRules.

@Override
public boolean applyLoadBalancerRules(Network network, List<LoadBalancingRule> rules) throws ResourceUnavailableException {
    if (rules == null || rules.isEmpty()) {
        return true;
    }
    DomainRouterVO elbVm = findElbVmForLb(rules.get(0));
    if (elbVm == null) {
        s_logger.warn("Unable to apply lb rules, ELB vm  doesn't exist in the network " + network.getId());
        throw new ResourceUnavailableException("Unable to apply lb rules", DataCenter.class, network.getDataCenterId());
    }
    if (elbVm.getState() == State.Running) {
        //resend all rules for the public ip
        long sourceIpId = _networkModel.getPublicIpAddress(rules.get(0).getSourceIp().addr(), network.getDataCenterId()).getId();
        List<LoadBalancerVO> lbs = _lbDao.listByIpAddress(sourceIpId);
        List<LoadBalancingRule> lbRules = new ArrayList<LoadBalancingRule>();
        for (LoadBalancerVO lb : lbs) {
            List<LbDestination> dstList = _lbMgr.getExistingDestinations(lb.getId());
            List<LbStickinessPolicy> policyList = _lbMgr.getStickinessPolicies(lb.getId());
            List<LbHealthCheckPolicy> hcPolicyList = _lbMgr.getHealthCheckPolicies(lb.getId());
            Ip sourceIp = _networkModel.getPublicIpAddress(lb.getSourceIpAddressId()).getAddress();
            LbSslCert sslCert = _lbMgr.getLbSslCert(lb.getId());
            LoadBalancingRule loadBalancing = new LoadBalancingRule(lb, dstList, policyList, hcPolicyList, sourceIp, sslCert, lb.getLbProtocol());
            lbRules.add(loadBalancing);
        }
        return applyLBRules(elbVm, lbRules, network.getId());
    } else if (elbVm.getState() == State.Stopped || elbVm.getState() == State.Stopping) {
        s_logger.debug("ELB VM is in " + elbVm.getState() + ", so not sending apply LoadBalancing rules commands to the backend");
        return true;
    } else {
        s_logger.warn("Unable to apply loadbalancing rules, ELB VM is not in the right state " + elbVm.getState());
        throw new ResourceUnavailableException("Unable to apply loadbalancing rules, ELB VM is not in the right state", VirtualRouter.class, elbVm.getId());
    }
}
Also used : LbSslCert(com.cloud.network.lb.LoadBalancingRule.LbSslCert) Ip(com.cloud.utils.net.Ip) LoadBalancerVO(com.cloud.network.dao.LoadBalancerVO) ArrayList(java.util.ArrayList) LbStickinessPolicy(com.cloud.network.lb.LoadBalancingRule.LbStickinessPolicy) VirtualRouter(com.cloud.network.router.VirtualRouter) LbDestination(com.cloud.network.lb.LoadBalancingRule.LbDestination) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) LbHealthCheckPolicy(com.cloud.network.lb.LoadBalancingRule.LbHealthCheckPolicy) DomainRouterVO(com.cloud.vm.DomainRouterVO)

Aggregations

LbHealthCheckPolicy (com.cloud.network.lb.LoadBalancingRule.LbHealthCheckPolicy)12 LbDestination (com.cloud.network.lb.LoadBalancingRule.LbDestination)10 LbStickinessPolicy (com.cloud.network.lb.LoadBalancingRule.LbStickinessPolicy)9 Ip (com.cloud.utils.net.Ip)9 LoadBalancerVO (com.cloud.network.dao.LoadBalancerVO)8 ArrayList (java.util.ArrayList)8 LoadBalancingRule (com.cloud.network.lb.LoadBalancingRule)5 LbSslCert (com.cloud.network.lb.LoadBalancingRule.LbSslCert)5 PublicIp (com.cloud.network.addr.PublicIp)4 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)3 DB (com.cloud.utils.db.DB)3 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)2 LBHealthCheckPolicyVO (com.cloud.network.LBHealthCheckPolicyVO)2 Network (com.cloud.network.Network)2 NetworkModel (com.cloud.network.NetworkModel)2 LoadBalancerDao (com.cloud.network.dao.LoadBalancerDao)2 LoadBalancingRulesManager (com.cloud.network.lb.LoadBalancingRulesManager)2 DomainRouterVO (com.cloud.vm.DomainRouterVO)2 ApplicationLoadBalancerRuleVO (org.apache.cloudstack.lb.ApplicationLoadBalancerRuleVO)2 CheckSshCommand (com.cloud.agent.api.check.CheckSshCommand)1