Search in sources :

Example 16 with LbHealthCheckPolicy

use of com.cloud.network.lb.LoadBalancingRule.LbHealthCheckPolicy in project cosmic by MissionCriticalCloud.

the class LoadBalancingRulesManagerImpl method getHealthCheckPolicies.

@Override
public List<LbHealthCheckPolicy> getHealthCheckPolicies(final long lbId) {
    final List<LbHealthCheckPolicy> healthCheckPolicies = new ArrayList<>();
    final List<LBHealthCheckPolicyVO> hcDbpolicies = _lb2healthcheckDao.listByLoadBalancerIdAndDisplayFlag(lbId, null);
    for (final LBHealthCheckPolicyVO policy : hcDbpolicies) {
        final String pingpath = policy.getpingpath();
        final 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 17 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)

Example 18 with LbHealthCheckPolicy

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

the class ElasticLoadBalancerManagerImpl method finalizeCommandsOnStart.

@Override
public boolean finalizeCommandsOnStart(Commands cmds, VirtualMachineProfile profile) {
    DomainRouterVO elbVm = _routerDao.findById(profile.getVirtualMachine().getId());
    DataCenterVO dcVo = _dcDao.findById(elbVm.getDataCenterId());
    NicProfile controlNic = null;
    Long guestNetworkId = null;
    if (profile.getHypervisorType() == HypervisorType.VMware && dcVo.getNetworkType() == NetworkType.Basic) {
        // for basic network mode, we will use the guest NIC for control NIC
        for (NicProfile nic : profile.getNics()) {
            if (nic.getTrafficType() == TrafficType.Guest && nic.getIPv4Address() != null) {
                controlNic = nic;
                guestNetworkId = nic.getNetworkId();
            }
        }
    } else {
        for (NicProfile nic : profile.getNics()) {
            if (nic.getTrafficType() == TrafficType.Control && nic.getIPv4Address() != null) {
                controlNic = nic;
            } else if (nic.getTrafficType() == TrafficType.Guest) {
                guestNetworkId = nic.getNetworkId();
            }
        }
    }
    if (controlNic == null) {
        s_logger.error("Control network doesn't exist for the ELB vm " + elbVm);
        return false;
    }
    cmds.addCommand("checkSsh", new CheckSshCommand(profile.getInstanceName(), controlNic.getIPv4Address(), 3922));
    // Re-apply load balancing rules
    List<LoadBalancerVO> lbs = _elbVmMapDao.listLbsForElbVm(elbVm.getId());
    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();
        LoadBalancingRule loadBalancing = new LoadBalancingRule(lb, dstList, policyList, hcPolicyList, sourceIp);
        lbRules.add(loadBalancing);
    }
    s_logger.debug("Found " + lbRules.size() + " load balancing rule(s) to apply as a part of ELB vm " + elbVm + " start.");
    if (!lbRules.isEmpty()) {
        createApplyLoadBalancingRulesCommands(lbRules, elbVm, cmds, guestNetworkId);
    }
    return true;
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) CheckSshCommand(com.cloud.agent.api.check.CheckSshCommand) Ip(com.cloud.utils.net.Ip) LoadBalancerVO(com.cloud.network.dao.LoadBalancerVO) ArrayList(java.util.ArrayList) LbStickinessPolicy(com.cloud.network.lb.LoadBalancingRule.LbStickinessPolicy) NicProfile(com.cloud.vm.NicProfile) LbDestination(com.cloud.network.lb.LoadBalancingRule.LbDestination) LbHealthCheckPolicy(com.cloud.network.lb.LoadBalancingRule.LbHealthCheckPolicy) DomainRouterVO(com.cloud.vm.DomainRouterVO)

Example 19 with LbHealthCheckPolicy

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

the class LoadBalancingRulesManagerImpl method createLBHealthCheckPolicy.

@Override
@DB
@ActionEvent(eventType = EventTypes.EVENT_LB_HEALTHCHECKPOLICY_CREATE, eventDescription = "create load balancer health check to load balancer", create = true)
public HealthCheckPolicy createLBHealthCheckPolicy(CreateLBHealthCheckPolicyCmd cmd) {
    CallContext caller = CallContext.current();
    /*
         * Validation of cmd Monitor interval must be greater than response
         * timeout
         */
    Map<String, String> paramMap = cmd.getFullUrlParams();
    if (paramMap.containsKey(ApiConstants.HEALTHCHECK_RESPONSE_TIMEOUT) && paramMap.containsKey(ApiConstants.HEALTHCHECK_INTERVAL_TIME)) {
        if (cmd.getResponsTimeOut() > cmd.getHealthCheckInterval())
            throw new InvalidParameterValueException("Failed to create HealthCheck policy : Monitor interval must be greater than response timeout");
    }
    /* Validation : check corresponding load balancer rule exist */
    LoadBalancerVO loadBalancer = _lbDao.findById(cmd.getLbRuleId());
    if (loadBalancer == null) {
        throw new InvalidParameterValueException("Failed: LB rule id: " + cmd.getLbRuleId() + " not present ");
    }
    _accountMgr.checkAccess(caller.getCallingAccount(), null, true, loadBalancer);
    if (loadBalancer.getState() == FirewallRule.State.Revoke) {
        throw new InvalidParameterValueException("Failed:  LB rule id: " + cmd.getLbRuleId() + " is in deleting state: ");
    }
    /*
         * Validate Whether LB Provider has the capabilities to support Health
         * Checks
         */
    if (!validateHealthCheck(cmd)) {
        throw new InvalidParameterValueException("Failed to create HealthCheck policy: Validation Failed (HealthCheck Policy is not supported by LB Provider for the LB rule id :" + cmd.getLbRuleId() + ")");
    }
    /* Validation : check for the multiple hc policies to the rule id */
    List<LBHealthCheckPolicyVO> hcPolicies = _lb2healthcheckDao.listByLoadBalancerId(cmd.getLbRuleId(), false);
    if (hcPolicies.size() > 0) {
        throw new InvalidParameterValueException("Failed to create HealthCheck policy: Already policy attached  for the LB Rule id :" + cmd.getLbRuleId());
    }
    /*
         * Specific validations using network element validator for specific
         * validations
         */
    LBHealthCheckPolicyVO hcpolicy = new LBHealthCheckPolicyVO(loadBalancer.getId(), cmd.getPingPath(), cmd.getDescription(), cmd.getResponsTimeOut(), cmd.getHealthCheckInterval(), cmd.getHealthyThreshold(), cmd.getUnhealthyThreshold());
    List<LbHealthCheckPolicy> hcPolicyList = new ArrayList<LbHealthCheckPolicy>();
    hcPolicyList.add(new LbHealthCheckPolicy(hcpolicy.getpingpath(), hcpolicy.getDescription(), hcpolicy.getResponseTime(), hcpolicy.getHealthcheckInterval(), hcpolicy.getHealthcheckThresshold(), hcpolicy.getUnhealthThresshold()));
    // Finally Insert into DB
    LBHealthCheckPolicyVO policy = new LBHealthCheckPolicyVO(loadBalancer.getId(), cmd.getPingPath(), cmd.getDescription(), cmd.getResponsTimeOut(), cmd.getHealthCheckInterval(), cmd.getHealthyThreshold(), cmd.getUnhealthyThreshold());
    Boolean forDisplay = cmd.getDisplay();
    if (forDisplay != null) {
        policy.setDisplay(forDisplay);
    }
    policy = _lb2healthcheckDao.persist(policy);
    return policy;
}
Also used : InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) LoadBalancerVO(com.cloud.network.dao.LoadBalancerVO) ArrayList(java.util.ArrayList) LbHealthCheckPolicy(com.cloud.network.lb.LoadBalancingRule.LbHealthCheckPolicy) LBHealthCheckPolicyVO(com.cloud.network.LBHealthCheckPolicyVO) CallContext(org.apache.cloudstack.context.CallContext) ActionEvent(com.cloud.event.ActionEvent) DB(com.cloud.utils.db.DB)

Aggregations

LbHealthCheckPolicy (com.cloud.network.lb.LoadBalancingRule.LbHealthCheckPolicy)19 LbDestination (com.cloud.network.lb.LoadBalancingRule.LbDestination)15 Ip (com.cloud.utils.net.Ip)14 LoadBalancerVO (com.cloud.network.dao.LoadBalancerVO)13 LbStickinessPolicy (com.cloud.network.lb.LoadBalancingRule.LbStickinessPolicy)13 ArrayList (java.util.ArrayList)12 LbSslCert (com.cloud.network.lb.LoadBalancingRule.LbSslCert)9 LoadBalancingRule (com.cloud.network.lb.LoadBalancingRule)8 PublicIp (com.cloud.network.addr.PublicIp)7 DB (com.cloud.utils.db.DB)5 LBHealthCheckPolicyVO (com.cloud.network.LBHealthCheckPolicyVO)4 NetworkModel (com.cloud.network.NetworkModel)4 LoadBalancerDao (com.cloud.network.dao.LoadBalancerDao)4 LoadBalancingRulesManager (com.cloud.network.lb.LoadBalancingRulesManager)4 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)3 Network (com.cloud.network.Network)3 LoadBalancerTO (com.cloud.agent.api.to.LoadBalancerTO)2 ActionEvent (com.cloud.event.ActionEvent)2 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)2 PublicIpAddress (com.cloud.network.PublicIpAddress)2