sureshanaparti commented on a change in pull request #4141: URL: https://github.com/apache/cloudstack/pull/4141#discussion_r520553964
########## File path: core/src/main/java/com/cloud/network/HAProxyConfigurator.java ########## @@ -531,42 +654,111 @@ private String getLbSubRuleForStickiness(final LoadBalancerTO lbTO) { } } if (httpbasedStickiness) { - result.addAll(dstWithCookieSubRule); + backendConfigs.addAll(dstWithCookieSubRule); } else { - result.addAll(dstSubRule); + backendConfigs.addAll(dstSubRule); } - result.add(stickinessSubRule); + backendConfigs.add(stickinessSubRule); } else { - result.addAll(dstSubRule); + backendConfigs.addAll(dstSubRule); } if (stickinessSubRule != null && !destsAvailable) { s_logger.warn("Haproxy stickiness policy for lb rule: " + lbTO.getSrcIp() + ":" + lbTO.getSrcPort() + ": Not Applied, cause: backends are unavailable"); } - if (publicPort == NetUtils.HTTP_PORT && !keepAliveEnabled || httpbasedStickiness) { + boolean http = false; + String cfgLbHttp = lbConfigsMap.get(LoadBalancerConfigKey.LbHttp.key()); + if (publicPort == NetUtils.HTTP_PORT && cfgLbHttp == null) { + http = true; + } else if (cfgLbHttp != null && cfgLbHttp.equalsIgnoreCase("true")) { + http = true; + } + + boolean keepAliveEnabled = lbCmd.keepAliveEnabled; + String cfgLbHttpKeepalive = lbConfigsMap.get(LoadBalancerConfigKey.LbHttpKeepalive.key()); + if (cfgLbHttpKeepalive != null && cfgLbHttpKeepalive.equalsIgnoreCase("true")) { + keepAliveEnabled = true; + } else if (cfgLbHttpKeepalive != null && cfgLbHttpKeepalive.equalsIgnoreCase("false")) { + keepAliveEnabled = false; + } + + if (http || httpbasedStickiness || sslOffloading) { sb = new StringBuilder(); sb.append("\t").append("mode http"); + frontendConfigs.add(sb.toString()); + backendConfigsForHttp.add(sb.toString()); + if (keepAliveEnabled) { + sb = new StringBuilder(); + sb.append("\t").append("no option forceclose"); + frontendConfigs.add(sb.toString()); + backendConfigsForHttp.add(sb.toString()); + } else { + sb = new StringBuilder(); + sb.append("\t").append("option httpclose"); + frontendConfigs.add(sb.toString()); + backendConfigsForHttp.add(sb.toString()); + } + } + + if (isTransparent) { + sb = new StringBuilder(); + sb.append("frontend ").append(poolName); result.add(sb.toString()); + result.addAll(frontendConfigs); sb = new StringBuilder(); - sb.append("\t").append("option httpclose"); + sb.append("\tacl local_subnet src ").append(lbCmd.getNetworkCidr()); + sb.append("\n\tuse_backend ").append(poolName).append("-backend-local if local_subnet"); + sb.append("\n\tdefault_backend ").append(poolName).append("-backend"); + sb.append("\n\n"); + sb.append("backend ").append(poolName).append("-backend"); + result.add(sb.toString()); + result.addAll(backendConfigsForHttp); + result.addAll(backendConfigs); + sb = new StringBuilder(); + sb.append("\t").append("source 0.0.0.0 usesrc clientip"); + sb.append("\n\n"); + sb.append("backend ").append(poolName).append("-backend-local"); result.add(sb.toString()); + result.addAll(backendConfigsForHttp); + result.addAll(backendConfigs); + } else { + // add line like this: "listen 65_37_141_30-80\n\tbind 65.37.141.30:80" + sb = new StringBuilder(); + sb.append("listen ").append(poolName); + result.add(sb.toString()); + result.addAll(frontendConfigs); + result.addAll(backendConfigs); } result.add(blankLine); return result; } - private String generateStatsRule(final LoadBalancerConfigCommand lbCmd, final String ruleName, final String statsIp) { + private String generateStatsRule(final LoadBalancerConfigCommand lbCmd, final String ruleName, final String statsIp, HashMap<String, String> networkLbConfigsMap) { + String lbStatsEnable = networkLbConfigsMap.get(LoadBalancerConfigKey.LbStatsEnable.key()); + if ( lbStatsEnable != null && ! lbStatsEnable.equalsIgnoreCase("true")) { + return ""; + } Review comment: for `lbStatsEnable` null, rule generated? ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org