weizhouapache commented on code in PR #11468:
URL: https://github.com/apache/cloudstack/pull/11468#discussion_r2291107577
##########
core/src/main/java/com/cloud/network/HAProxyConfigurator.java:
##########
@@ -520,61 +544,69 @@ private List<String> getRulesForPool(final LoadBalancerTO
lbTO, final boolean ke
destsAvailable = true;
}
- Boolean httpbasedStickiness = false;
+ boolean httpbasedStickiness = false;
/* attach stickiness sub rule only if the destinations are available */
- if (stickinessSubRule != null && destsAvailable == true) {
+ if (stickinessSubRule != null && destsAvailable) {
for (final StickinessPolicyTO stickinessPolicy :
lbTO.getStickinessPolicies()) {
if (stickinessPolicy == null) {
continue;
}
if
(StickinessMethodType.LBCookieBased.getName().equalsIgnoreCase(stickinessPolicy.getMethodName())
||
StickinessMethodType.AppCookieBased.getName().equalsIgnoreCase(stickinessPolicy.getMethodName()))
{
httpbasedStickiness = true;
+ break;
}
}
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) {
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) {
- sb = new StringBuilder();
- sb.append("\t").append("mode http");
- result.add(sb.toString());
- sb = new StringBuilder();
- sb.append("\t").append("option httpclose");
- result.add(sb.toString());
+ boolean keepAliveEnabled = lbCmd.keepAliveEnabled;
+ boolean http = (publicPort == NetUtils.HTTP_PORT && !keepAliveEnabled);
+ if (http || httpbasedStickiness || sslOffloading) {
+ frontendConfigs.add("\tmode http");
+ String keepAliveLine = keepAliveEnabled ? "\tno option forceclose"
: "\toption httpclose";
+ frontendConfigs.add(keepAliveLine);
}
+ // add line like this: "listen 65_37_141_30-80\n\tbind
65.37.141.30:80"
+ result.add(String.format("listen %s", poolName));
+ result.addAll(frontendConfigs);
+
String cidrList = lbTO.getCidrList();
if (StringUtils.isNotBlank(cidrList)) {
result.add(String.format("\tacl network_allowed src %s
\n\ttcp-request connection reject if !network_allowed", cidrList));
}
+ result.addAll(backendConfigs);
result.add(blankLine);
return result;
}
private String generateStatsRule(final LoadBalancerConfigCommand lbCmd,
final String ruleName, final String statsIp) {
final StringBuilder rule = new StringBuilder("\nlisten
").append(ruleName).append("\n\tbind
").append(statsIp).append(":").append(lbCmd.lbStatsPort);
// TODO DH: write test for this in both cases
- if (!lbCmd.keepAliveEnabled) {
- logger.info("Haproxy mode http enabled");
- rule.append("\n\tmode http\n\toption httpclose");
+ rule.append("\n\tmode http");
+ if (lbCmd.keepAliveEnabled) {
+ logger.info("Haproxy option http-keep-alive enabled");
+ } else {
+ logger.info("Haproxy option httpclose enabled");
+ rule.append("\n\toption httpclose");
}
rule.append("\n\tstats enable\n\tstats uri ")
- .append(lbCmd.lbStatsUri)
- .append("\n\tstats realm Haproxy\\ Statistics\n\tstats auth ")
- .append(lbCmd.lbStatsAuth);
- rule.append("\n");
+ .append(lbCmd.lbStatsUri)
+ .append("\n\tstats realm Haproxy\\ Statistics\n\tstats auth
")
+ .append(lbCmd.lbStatsAuth)
+ .append("\n");
Review Comment:
this is auto-format by intelliJ IDEA. I guess it is ok ?
--
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]