bug 12891: added cookie to destination if it is http based sticky.

This commit is contained in:
Naredula Janardhana Reddy 2012-01-06 10:17:55 +05:30
parent 144265dbf4
commit d683e30e28
2 changed files with 20 additions and 6 deletions

View File

@ -509,6 +509,9 @@ public class HAProxyConfigurator implements LoadBalancerConfigurator {
int i = 0;
Boolean destsAvailable = false;
String stickinessSubRule = getLbSubRuleForStickiness(lbTO);
List<String> dstSubRule = new ArrayList<String>();
List<String> dstWithCookieSubRule = new ArrayList<String>();
for (DestinationTO dest : lbTO.getDestinations()) {
// add line like this: "server 65_37_141_30-80_3 10.1.1.4:80 check"
if (dest.isRevoked()) {
@ -519,15 +522,18 @@ public class HAProxyConfigurator implements LoadBalancerConfigurator {
.append(Integer.toString(i++)).append(" ")
.append(dest.getDestIp()).append(":")
.append(dest.getDestPort()).append(" check");
result.add(sb.toString());
dstSubRule.add(sb.toString());
if (stickinessSubRule != null) {
sb.append(" cookie ").append(dest.getDestIp().replace(".", "_"))
.append('-').append(dest.getDestPort()).toString();
dstWithCookieSubRule.add(sb.toString());
}
destsAvailable = true;
}
String stickinessSubRule = getLbSubRuleForStickiness(lbTO);
Boolean httpbasedStickiness = false;
/* attach stickiness sub rule only if the destinations are avilable */
/* attach stickiness sub rule only if the destinations are available */
if ((stickinessSubRule != null) && (destsAvailable == true)) {
result.add(stickinessSubRule);
for (StickinessPolicyTO stickinessPolicy : lbTO.getStickinessPolicies()) {
if (stickinessPolicy == null)
continue;
@ -535,6 +541,14 @@ public class HAProxyConfigurator implements LoadBalancerConfigurator {
httpbasedStickiness = true;
}
}
if (httpbasedStickiness) {
result.addAll(dstWithCookieSubRule);
}else {
result.addAll(dstSubRule);
}
result.add(stickinessSubRule);
}else {
result.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");

View File

@ -312,7 +312,7 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
method.addParam("nocache", false, "This option is recommended in conjunction with the insert mode when there is a cache between the client and HAProxy, as it ensures that a cacheable response will be tagged non-cacheable if a cookie needs to be inserted. This is important because if all persistence cookies are added on a cacheable home page for instance, then all customers will then fetch the page from an outer cache and will all share the same persistence cookie, leading to one server receiving much more traffic than others. See also the insert and postonly options. ",true);
method.addParam("indirect", false, "When this option is specified in insert mode, cookies will only be added when the server was not reached after a direct access, which means that only when a server is elected after applying a load-balancing algorithm, or after a redispatch, then the cookie will be inserted. If the client has all the required information to connect to the same server next time, no further cookie will be inserted. In all cases, when the indirect option is used in insert mode, the cookie is always removed from the requests transmitted to the server. The persistence mechanism then becomes totally transparent from the application point of view.",true);
method.addParam("postonly",false,"This option ensures that cookie insertion will only be performed on responses to POST requests. It is an alternative to the nocache option, because POST responses are not cacheable, so this ensures that the persistence cookie will never get cached.Since most sites do not need any sort of persistence before the first POST which generally is a login request, this is a very efficient method to optimize caching without risking to find a persistence cookie in the cache. See also the insert and nocache options.",true);
method.addParam("domain",false,"This option allows to specify the domain at which a cookie is inserted. It requires exactly one parameter: a valid domain name. If the domain begins with a dot, the browser is allowed to use it for any host ending with that name. It is also possible to specify several domain names by invoking this option multiple times. Some browsers might have small limits on the number of domains, so be careful when doing that. For the record, sending 10 domains to MSIE 6 or Firefox 2 works as expected.",true);
method.addParam("domain",false,"This option allows to specify the domain at which a cookie is inserted. It requires exactly one parameter: a valid domain name. If the domain begins with a dot, the browser is allowed to use it for any host ending with that name. It is also possible to specify several domain names by invoking this option multiple times. Some browsers might have small limits on the number of domains, so be careful when doing that. For the record, sending 10 domains to MSIE 6 or Firefox 2 works as expected.",false);
methodList.add(method);
method = new LbStickinessMethod(StickinessMethodType.AppCookieBased,"This is app session based sticky method,Define session stickiness on an existing application cookie. it can be used only for a specific http traffic");