soreana commented on a change in pull request #4141:
URL: https://github.com/apache/cloudstack/pull/4141#discussion_r670501607



##########
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());
+            }

Review comment:
       I replaced it with String.format. In my opinion, writing a method for it 
would be over engineering :D




-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to