CLOUDSTACK-1851 Health Check monitor not getting created on Netscaler device in Basic zone setup.
Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/16865014 Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/16865014 Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/16865014 Branch: refs/heads/vmware-datamodel Commit: 16865014a05ab04bb608a8122a7229b2b0ae3421 Parents: f1c794d Author: Rajesh Battala <[email protected]> Authored: Wed Apr 17 18:22:30 2013 +0530 Committer: Murali Reddy <[email protected]> Committed: Thu May 2 11:20:43 2013 +0530 ---------------------------------------------------------------------- .../cloud/network/element/NetscalerElement.java | 70 ++++++++++++++- 1 files changed, 68 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/16865014/plugins/network-elements/netscaler/src/com/cloud/network/element/NetscalerElement.java ---------------------------------------------------------------------- diff --git a/plugins/network-elements/netscaler/src/com/cloud/network/element/NetscalerElement.java b/plugins/network-elements/netscaler/src/com/cloud/network/element/NetscalerElement.java index 2bbdb04..7bd9c2e 100644 --- a/plugins/network-elements/netscaler/src/com/cloud/network/element/NetscalerElement.java +++ b/plugins/network-elements/netscaler/src/com/cloud/network/element/NetscalerElement.java @@ -19,6 +19,8 @@ package com.cloud.network.element; import com.cloud.agent.AgentManager; import com.cloud.agent.api.Answer; import com.cloud.agent.api.routing.GlobalLoadBalancerConfigCommand; +import com.cloud.agent.api.routing.HealthCheckLBConfigAnswer; +import com.cloud.agent.api.routing.HealthCheckLBConfigCommand; import com.cloud.agent.api.routing.LoadBalancerConfigCommand; import com.cloud.agent.api.routing.SetStaticNatRulesAnswer; import com.cloud.agent.api.routing.SetStaticNatRulesCommand; @@ -682,7 +684,7 @@ public class NetscalerElement extends ExternalLoadBalancerDeviceManagerImpl impl List<LbDestination> destinations = rule.getDestinations(); if ((destinations != null && !destinations.isEmpty()) || rule.isAutoScaleConfig()) { - LoadBalancerTO loadBalancer = new LoadBalancerTO(lbUuid, srcIp, srcPort, protocol, algorithm, revoked, false, false, destinations, rule.getStickinessPolicies()); + LoadBalancerTO loadBalancer = new LoadBalancerTO(lbUuid, srcIp, srcPort, protocol, algorithm, revoked, false, false, destinations, rule.getStickinessPolicies(), rule.getHealthCheckPolicies()); if (rule.isAutoScaleConfig()) { loadBalancer.setAutoScaleVmGroup(rule.getAutoScaleVmGroup()); } @@ -808,11 +810,75 @@ public class NetscalerElement extends ExternalLoadBalancerDeviceManagerImpl impl return null; } + public List<LoadBalancerTO> getElasticLBRulesHealthCheck(Network network, List<? extends FirewallRule> rules) + throws ResourceUnavailableException { + + HealthCheckLBConfigAnswer answer = null; + List<LoadBalancingRule> loadBalancingRules = new ArrayList<LoadBalancingRule>(); + for (FirewallRule rule : rules) { + if (rule.getPurpose().equals(Purpose.LoadBalancing)) { + loadBalancingRules.add((LoadBalancingRule) rule); + } + } + + if (loadBalancingRules == null || loadBalancingRules.isEmpty()) { + return null; + } + + String errMsg = null; + ExternalLoadBalancerDeviceVO lbDeviceVO = getExternalLoadBalancerForNetwork(network); + + if (lbDeviceVO == null) { + 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"); + return null; + } + + if (!isNetscalerDevice(lbDeviceVO.getDeviceName())) { + errMsg = "There are no NetScaler load balancer assigned for this network. So NetScaler element can not be handle elastic load balancer rules."; + s_logger.error(errMsg); + throw new ResourceUnavailableException(errMsg, this.getClass(), 0); + } + + List<LoadBalancerTO> loadBalancersToApply = new ArrayList<LoadBalancerTO>(); + for (int i = 0; i < loadBalancingRules.size(); i++) { + LoadBalancingRule rule = loadBalancingRules.get(i); + boolean revoked = (rule.getState().equals(FirewallRule.State.Revoke)); + String protocol = rule.getProtocol(); + String algorithm = rule.getAlgorithm(); + String lbUuid = rule.getUuid(); + String srcIp = _networkMgr.getIp(rule.getSourceIpAddressId()).getAddress().addr(); + int srcPort = rule.getSourcePortStart(); + List<LbDestination> destinations = rule.getDestinations(); + + if ((destinations != null && !destinations.isEmpty()) || rule.isAutoScaleConfig()) { + LoadBalancerTO loadBalancer = new LoadBalancerTO(lbUuid, srcIp, srcPort, protocol, algorithm, revoked, + false, false, destinations, null, rule.getHealthCheckPolicies()); + loadBalancersToApply.add(loadBalancer); + } + } + + if (loadBalancersToApply.size() > 0) { + int numLoadBalancersForCommand = loadBalancersToApply.size(); + LoadBalancerTO[] loadBalancersForCommand = loadBalancersToApply + .toArray(new LoadBalancerTO[numLoadBalancersForCommand]); + HealthCheckLBConfigCommand cmd = new HealthCheckLBConfigCommand(loadBalancersForCommand); + HostVO externalLoadBalancer = _hostDao.findById(lbDeviceVO.getHostId()); + answer = (HealthCheckLBConfigAnswer) _agentMgr.easySend(externalLoadBalancer.getId(), cmd); + return answer.getLoadBalancers(); + } + return null; + } + public List<LoadBalancerTO> updateHealthChecks(Network network, List<LoadBalancingRule> lbrules) { if (canHandle(network, Service.Lb)) { try { - return getLBHealthChecks(network, lbrules); + + if (isBasicZoneNetwok(network)) { + return getElasticLBRulesHealthCheck(network, lbrules); + } else { + return getLBHealthChecks(network, lbrules); + } } catch (ResourceUnavailableException e) { s_logger.error("Error in getting the LB Rules from NetScaler " + e); }
