|
19 | 19 | import com.cloud.agent.AgentManager; |
20 | 20 | import com.cloud.agent.api.Answer; |
21 | 21 | import com.cloud.agent.api.routing.GlobalLoadBalancerConfigCommand; |
| 22 | +import com.cloud.agent.api.routing.HealthCheckLBConfigAnswer; |
| 23 | +import com.cloud.agent.api.routing.HealthCheckLBConfigCommand; |
22 | 24 | import com.cloud.agent.api.routing.LoadBalancerConfigCommand; |
23 | 25 | import com.cloud.agent.api.routing.SetStaticNatRulesAnswer; |
24 | 26 | import com.cloud.agent.api.routing.SetStaticNatRulesCommand; |
@@ -682,7 +684,7 @@ public boolean applyElasticLoadBalancerRules(Network network, List<? extends Fir |
682 | 684 | List<LbDestination> destinations = rule.getDestinations(); |
683 | 685 |
|
684 | 686 | if ((destinations != null && !destinations.isEmpty()) || rule.isAutoScaleConfig()) { |
685 | | - LoadBalancerTO loadBalancer = new LoadBalancerTO(lbUuid, srcIp, srcPort, protocol, algorithm, revoked, false, false, destinations, rule.getStickinessPolicies()); |
| 687 | + LoadBalancerTO loadBalancer = new LoadBalancerTO(lbUuid, srcIp, srcPort, protocol, algorithm, revoked, false, false, destinations, rule.getStickinessPolicies(), rule.getHealthCheckPolicies()); |
686 | 688 | if (rule.isAutoScaleConfig()) { |
687 | 689 | loadBalancer.setAutoScaleVmGroup(rule.getAutoScaleVmGroup()); |
688 | 690 | } |
@@ -808,11 +810,75 @@ private ExternalLoadBalancerDeviceVO getNetScalerForEIP(StaticNat rule) { |
808 | 810 | return null; |
809 | 811 | } |
810 | 812 |
|
| 813 | + public List<LoadBalancerTO> getElasticLBRulesHealthCheck(Network network, List<? extends FirewallRule> rules) |
| 814 | + throws ResourceUnavailableException { |
| 815 | + |
| 816 | + HealthCheckLBConfigAnswer answer = null; |
| 817 | + List<LoadBalancingRule> loadBalancingRules = new ArrayList<LoadBalancingRule>(); |
| 818 | + for (FirewallRule rule : rules) { |
| 819 | + if (rule.getPurpose().equals(Purpose.LoadBalancing)) { |
| 820 | + loadBalancingRules.add((LoadBalancingRule) rule); |
| 821 | + } |
| 822 | + } |
| 823 | + |
| 824 | + if (loadBalancingRules == null || loadBalancingRules.isEmpty()) { |
| 825 | + return null; |
| 826 | + } |
| 827 | + |
| 828 | + String errMsg = null; |
| 829 | + ExternalLoadBalancerDeviceVO lbDeviceVO = getExternalLoadBalancerForNetwork(network); |
| 830 | + |
| 831 | + if (lbDeviceVO == null) { |
| 832 | + s_logger.warn("There is no external load balancer device assigned to this network either network is not implement are already shutdown so just returning"); |
| 833 | + return null; |
| 834 | + } |
| 835 | + |
| 836 | + if (!isNetscalerDevice(lbDeviceVO.getDeviceName())) { |
| 837 | + errMsg = "There are no NetScaler load balancer assigned for this network. So NetScaler element can not be handle elastic load balancer rules."; |
| 838 | + s_logger.error(errMsg); |
| 839 | + throw new ResourceUnavailableException(errMsg, this.getClass(), 0); |
| 840 | + } |
| 841 | + |
| 842 | + List<LoadBalancerTO> loadBalancersToApply = new ArrayList<LoadBalancerTO>(); |
| 843 | + for (int i = 0; i < loadBalancingRules.size(); i++) { |
| 844 | + LoadBalancingRule rule = loadBalancingRules.get(i); |
| 845 | + boolean revoked = (rule.getState().equals(FirewallRule.State.Revoke)); |
| 846 | + String protocol = rule.getProtocol(); |
| 847 | + String algorithm = rule.getAlgorithm(); |
| 848 | + String lbUuid = rule.getUuid(); |
| 849 | + String srcIp = _networkMgr.getIp(rule.getSourceIpAddressId()).getAddress().addr(); |
| 850 | + int srcPort = rule.getSourcePortStart(); |
| 851 | + List<LbDestination> destinations = rule.getDestinations(); |
| 852 | + |
| 853 | + if ((destinations != null && !destinations.isEmpty()) || rule.isAutoScaleConfig()) { |
| 854 | + LoadBalancerTO loadBalancer = new LoadBalancerTO(lbUuid, srcIp, srcPort, protocol, algorithm, revoked, |
| 855 | + false, false, destinations, null, rule.getHealthCheckPolicies()); |
| 856 | + loadBalancersToApply.add(loadBalancer); |
| 857 | + } |
| 858 | + } |
| 859 | + |
| 860 | + if (loadBalancersToApply.size() > 0) { |
| 861 | + int numLoadBalancersForCommand = loadBalancersToApply.size(); |
| 862 | + LoadBalancerTO[] loadBalancersForCommand = loadBalancersToApply |
| 863 | + .toArray(new LoadBalancerTO[numLoadBalancersForCommand]); |
| 864 | + HealthCheckLBConfigCommand cmd = new HealthCheckLBConfigCommand(loadBalancersForCommand); |
| 865 | + HostVO externalLoadBalancer = _hostDao.findById(lbDeviceVO.getHostId()); |
| 866 | + answer = (HealthCheckLBConfigAnswer) _agentMgr.easySend(externalLoadBalancer.getId(), cmd); |
| 867 | + return answer.getLoadBalancers(); |
| 868 | + } |
| 869 | + return null; |
| 870 | + } |
| 871 | + |
811 | 872 | public List<LoadBalancerTO> updateHealthChecks(Network network, List<LoadBalancingRule> lbrules) { |
812 | 873 |
|
813 | 874 | if (canHandle(network, Service.Lb)) { |
814 | 875 | try { |
815 | | - return getLBHealthChecks(network, lbrules); |
| 876 | + |
| 877 | + if (isBasicZoneNetwok(network)) { |
| 878 | + return getElasticLBRulesHealthCheck(network, lbrules); |
| 879 | + } else { |
| 880 | + return getLBHealthChecks(network, lbrules); |
| 881 | + } |
816 | 882 | } catch (ResourceUnavailableException e) { |
817 | 883 | s_logger.error("Error in getting the LB Rules from NetScaler " + e); |
818 | 884 | } |
|
0 commit comments