mirror of https://github.com/apache/cloudstack.git
Summary of HAProxy stickines param changes:
- converted all mandatory params to optional, and internally fill with default value before sending to haproxy. default value is available through description. - accept holdtime without units.
This commit is contained in:
parent
44c172bdc2
commit
31fe8bd815
|
|
@ -315,10 +315,6 @@ public class HAProxyConfigurator implements LoadBalancerConfigurator {
|
|||
*/
|
||||
private String getLbSubRuleForStickiness(LoadBalancerTO lbTO) {
|
||||
int i = 0;
|
||||
/* This is timeformat as per the haproxy doc, d=day, h=hour m=minute, s=seconds
|
||||
* example: 20s 30m 400h 20d
|
||||
*/
|
||||
String timeEndChar = "dhms";
|
||||
|
||||
if (lbTO.getStickinessPolicies() == null)
|
||||
return null;
|
||||
|
|
@ -338,7 +334,7 @@ public class HAProxyConfigurator implements LoadBalancerConfigurator {
|
|||
*/
|
||||
if (StickinessMethodType.LBCookieBased.getName().equalsIgnoreCase(stickinessPolicy.getMethodName())) {
|
||||
/* Default Values */
|
||||
String name = null; // optional
|
||||
String cookieName = null; // optional
|
||||
String mode ="insert "; // optional
|
||||
Boolean indirect = false; // optional
|
||||
Boolean nocache = false; // optional
|
||||
|
|
@ -348,7 +344,7 @@ public class HAProxyConfigurator implements LoadBalancerConfigurator {
|
|||
for(Pair<String,String> paramKV :paramsList){
|
||||
String key = paramKV.first();
|
||||
String value = paramKV.second();
|
||||
if ("cookie-name".equalsIgnoreCase(key)) name = value;
|
||||
if ("cookie-name".equalsIgnoreCase(key)) cookieName = value;
|
||||
if ("mode".equalsIgnoreCase(key)) mode = value;
|
||||
if ("domain".equalsIgnoreCase(key)) {
|
||||
if (domainSb == null) {
|
||||
|
|
@ -361,16 +357,16 @@ public class HAProxyConfigurator implements LoadBalancerConfigurator {
|
|||
if ("nocache".equalsIgnoreCase(key)) nocache = true;
|
||||
if ("postonly".equalsIgnoreCase(key)) postonly = true;
|
||||
}
|
||||
if (name == null) {// re-check all mandatory params
|
||||
if (cookieName == null) {// re-check all haproxy mandatory params
|
||||
StringBuilder tempSb = new StringBuilder();
|
||||
String srcip = lbTO.getSrcIp();
|
||||
if (srcip == null)
|
||||
srcip = "TESTCOOKIE";
|
||||
tempSb.append("lbcooki_").append(srcip.hashCode())
|
||||
.append("_").append(lbTO.getSrcPort());
|
||||
name = tempSb.toString();
|
||||
cookieName = tempSb.toString();
|
||||
}
|
||||
sb.append("\t").append("cookie ").append(name).append(" ").append(mode).append(" ");
|
||||
sb.append("\t").append("cookie ").append(cookieName).append(" ").append(mode).append(" ");
|
||||
if (indirect) sb.append("indirect ");
|
||||
if (nocache) sb.append("nocache ");
|
||||
if (postonly) sb.append("postonly ");
|
||||
|
|
@ -397,9 +393,9 @@ public class HAProxyConfigurator implements LoadBalancerConfigurator {
|
|||
* <path-parameters|query-string>]
|
||||
*/
|
||||
/* example: appsession JSESSIONID len 52 timeout 3h */
|
||||
String name = null; // required
|
||||
String length = null; // required
|
||||
String holdtime = null; // required
|
||||
String cookieName = null; // optional
|
||||
String length = "52"; // optional
|
||||
String holdtime = "3h"; // optional
|
||||
String mode = null; // optional
|
||||
Boolean requestlearn = false; // optional
|
||||
Boolean prefix = false; // optional
|
||||
|
|
@ -407,24 +403,23 @@ public class HAProxyConfigurator implements LoadBalancerConfigurator {
|
|||
for(Pair<String,String> paramKV :paramsList){
|
||||
String key = paramKV.first();
|
||||
String value = paramKV.second();
|
||||
if ("cookie-name".equalsIgnoreCase(key)) name = value;
|
||||
if ("cookie-name".equalsIgnoreCase(key)) cookieName = value;
|
||||
if ("length".equalsIgnoreCase(key)) length = value;
|
||||
if ("holdtime".equalsIgnoreCase(key)) holdtime = value;
|
||||
if ("mode".equalsIgnoreCase(key)) mode = value;
|
||||
if ("request-learn".equalsIgnoreCase(key)) requestlearn = true;
|
||||
if ("prefix".equalsIgnoreCase(key)) prefix = true;
|
||||
}
|
||||
if ((name == null) || (length == null) || (holdtime == null)) {
|
||||
/*
|
||||
* Error is silently swallowed.
|
||||
* Not supposed to reach here, validation of params are
|
||||
* done at the higher layer
|
||||
*/
|
||||
s_logger.warn("Haproxy stickiness policy for lb rule: " + lbTO.getSrcIp() + ":" + lbTO.getSrcPort() +": Not Applied, cause: length,holdtime or name is null");
|
||||
return null;
|
||||
if (cookieName == null) {// re-check all haproxy mandatory params
|
||||
StringBuilder tempSb = new StringBuilder();
|
||||
String srcip = lbTO.getSrcIp();
|
||||
if (srcip == null)
|
||||
srcip = "TESTCOOKIE";
|
||||
tempSb.append("appcookie_").append(srcip.hashCode())
|
||||
.append("_").append(lbTO.getSrcPort());
|
||||
cookieName = tempSb.toString();
|
||||
}
|
||||
|
||||
sb.append("\t").append("appsession ").append(name)
|
||||
sb.append("\t").append("appsession ").append(cookieName)
|
||||
.append(" len ").append(length).append(" timeout ")
|
||||
.append(holdtime).append(" ");
|
||||
if (prefix) sb.append("prefix ");
|
||||
|
|
|
|||
|
|
@ -282,9 +282,9 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
|
|||
* <path-parameters|query-string>]
|
||||
*/
|
||||
/* example: appsession JSESSIONID len 52 timeout 3h */
|
||||
String cookieName = null; // required
|
||||
String length = null; // required
|
||||
String holdTime = null; // required
|
||||
String cookieName = null; // optional
|
||||
String length = null; // optional
|
||||
String holdTime = null; // optional
|
||||
|
||||
for (Pair<String, String> paramKV : paramsList) {
|
||||
String key = paramKV.first();
|
||||
|
|
@ -296,13 +296,11 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
|
|||
if ("holdtime".equalsIgnoreCase(key))
|
||||
holdTime = value;
|
||||
}
|
||||
if ((cookieName == null) || (length == null) || (holdTime == null)) {
|
||||
throw new InvalidParameterValueException("Failed LB in validation rule id: " + rule.getId() + " Cause: length, holdtime or cookie-name is null.");
|
||||
}
|
||||
if (!containsOnlyNumbers(length, null)) {
|
||||
|
||||
if ((length != null) && (!containsOnlyNumbers(length, null))) {
|
||||
throw new InvalidParameterValueException("Failed LB in validation rule id: " + rule.getId() + " Cause: length is not a number: " + length);
|
||||
}
|
||||
if (!containsOnlyNumbers(holdTime, timeEndChar)) {
|
||||
if ((holdTime != null) && (!containsOnlyNumbers(holdTime, timeEndChar) && !containsOnlyNumbers(holdTime, null))) {
|
||||
throw new InvalidParameterValueException("Failed LB in validation rule id: " + rule.getId() + " Cause: holdtime is not in timeformat: " + holdTime);
|
||||
}
|
||||
}
|
||||
|
|
@ -452,12 +450,12 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
|
|||
|
||||
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");
|
||||
method.addParam("cookie-name", true, "This is the name of the cookie used by the application and which LB will have to learn for each new session", false);
|
||||
method.addParam("length", true, "This is the max number of characters that will be memorized and checked in each cookie value", false);
|
||||
method.addParam("cookie-name", false, "This is the name of the cookie used by the application and which LB will have to learn for each new session. Default value: Auto geneared based on ip", false);
|
||||
method.addParam("length", false, "This is the max number of characters that will be memorized and checked in each cookie value. Default value:52", false);
|
||||
method.addParam(
|
||||
"holdtime",
|
||||
true,
|
||||
"This is the time after which the cookie will be removed from memory if unused. The value should be in the format Example : 20s or 30m or 4h or 5d . only seconds(s), minutes(m) hours(h) and days(d) are valid , cannot use th combinations like 20h30m. ",
|
||||
false,
|
||||
"This is the time after which the cookie will be removed from memory if unused. The value should be in the format Example : 20s or 30m or 4h or 5d . only seconds(s), minutes(m) hours(h) and days(d) are valid , cannot use th combinations like 20h30m. Default value:3h ",
|
||||
false);
|
||||
method.addParam(
|
||||
"request-learn",
|
||||
|
|
@ -477,8 +475,8 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
|
|||
methodList.add(method);
|
||||
|
||||
method = new LbStickinessMethod(StickinessMethodType.SourceBased, "This is source based Stickiness method, it can be used for any type of protocol.");
|
||||
method.addParam("tablesize", false, "Size of table to store source ip addresses. example: tablesize=200k or 300m or 400g", false);
|
||||
method.addParam("expire", false, "Entry in source ip table will expire after expire duration. units can be s,m,h,d . example: expire=30m 20s 50h 4d", false);
|
||||
method.addParam("tablesize", false, "Size of table to store source ip addresses. example: tablesize=200k or 300m or 400g. Default value:200k", false);
|
||||
method.addParam("expire", false, "Entry in source ip table will expire after expire duration. units can be s,m,h,d . example: expire=30m 20s 50h 4d. Default value:3h", false);
|
||||
methodList.add(method);
|
||||
|
||||
Gson gson = new Gson();
|
||||
|
|
|
|||
Loading…
Reference in New Issue