Skip to content

Commit 1686501

Browse files
rajesh-battalaMurali Reddy
authored andcommitted
CLOUDSTACK-1851 Health Check monitor not getting created on Netscaler device in Basic zone setup.
1 parent f1c794d commit 1686501

1 file changed

Lines changed: 68 additions & 2 deletions

File tree

plugins/network-elements/netscaler/src/com/cloud/network/element/NetscalerElement.java

Lines changed: 68 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
import com.cloud.agent.AgentManager;
2020
import com.cloud.agent.api.Answer;
2121
import com.cloud.agent.api.routing.GlobalLoadBalancerConfigCommand;
22+
import com.cloud.agent.api.routing.HealthCheckLBConfigAnswer;
23+
import com.cloud.agent.api.routing.HealthCheckLBConfigCommand;
2224
import com.cloud.agent.api.routing.LoadBalancerConfigCommand;
2325
import com.cloud.agent.api.routing.SetStaticNatRulesAnswer;
2426
import com.cloud.agent.api.routing.SetStaticNatRulesCommand;
@@ -682,7 +684,7 @@ public boolean applyElasticLoadBalancerRules(Network network, List<? extends Fir
682684
List<LbDestination> destinations = rule.getDestinations();
683685

684686
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());
686688
if (rule.isAutoScaleConfig()) {
687689
loadBalancer.setAutoScaleVmGroup(rule.getAutoScaleVmGroup());
688690
}
@@ -808,11 +810,75 @@ private ExternalLoadBalancerDeviceVO getNetScalerForEIP(StaticNat rule) {
808810
return null;
809811
}
810812

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+
811872
public List<LoadBalancerTO> updateHealthChecks(Network network, List<LoadBalancingRule> lbrules) {
812873

813874
if (canHandle(network, Service.Lb)) {
814875
try {
815-
return getLBHealthChecks(network, lbrules);
876+
877+
if (isBasicZoneNetwok(network)) {
878+
return getElasticLBRulesHealthCheck(network, lbrules);
879+
} else {
880+
return getLBHealthChecks(network, lbrules);
881+
}
816882
} catch (ResourceUnavailableException e) {
817883
s_logger.error("Error in getting the LB Rules from NetScaler " + e);
818884
}

0 commit comments

Comments
 (0)