Bug 11845:

Summary of Changes:
    - created a generic way for LB rule validations, so as LB device(like Haproxy) specific validations can be done syncronously.
    - Removed asyncronous validations from Haproxy and done syncronously.
This commit is contained in:
Naredula Janardhana Reddy 2012-02-01 18:01:11 +05:30
parent a072cdfec6
commit aea81205ef
11 changed files with 273 additions and 100 deletions

View File

@ -17,4 +17,12 @@ public interface LoadBalancingServiceProvider extends NetworkElement {
boolean applyLBRules(Network network, List<LoadBalancingRule> rules) throws ResourceUnavailableException;
IpDeployer getIpDeployer(Network network);
/**
* Validate rules
* @param network
* @param rule
* @return true/false. true should be return if there are no validations. false should be return if any oneof the validation fails.
* @throws
*/
boolean validateLBRule(Network network, LoadBalancingRule rule);
}

View File

@ -139,13 +139,18 @@ public class LoadBalancingRule implements FirewallRule, LoadBalancer{
private List<Pair<String, String>> _params;
private boolean _revoke;
public LbStickinessPolicy(String methodName, List<Pair<String, String>> params,
boolean revoke) {
public LbStickinessPolicy(String methodName, List<Pair<String, String>> params, boolean revoke) {
this._methodName = methodName;
this._params = params;
this._revoke = revoke;
}
public LbStickinessPolicy(String methodName, List<Pair<String, String>> params) {
this._methodName = methodName;
this._params = params;
this._revoke = false;
}
public String getMethodName() {
return _methodName;
}

View File

@ -151,37 +151,7 @@ public class HAProxyConfigurator implements LoadBalancerConfigurator {
result.add(getBlankLine());
return result;
}
/*
* This function detects numbers like 12 ,32h ,42m .. etc,.
* 1) plain number like 12
* 2) time or tablesize like 12h, 34m, 45k, 54m , here last character is non-digit but from known characters .
*
*/
private boolean containsOnlyNumbers(String str, String endChar) {
if (str == null) return false;
String number = str;
if (endChar != null){
boolean matchedEndChar = false;
if (str.length() < 2) return false; // atleast one numeric and one char. example: 3h
char strEnd = str.toCharArray()[str.length()-1];
for (char c: endChar.toCharArray()){
if (strEnd == c){
number = str.substring(0, str.length()-1);
matchedEndChar = true;
break;
}
}
if (!matchedEndChar) return false;
}
try {
int i = Integer.parseInt(number);
}
catch (NumberFormatException e){
return false;
}
return true;
}
/*
cookie <name> [ rewrite | insert | prefix ] [ indirect ] [ nocache ]
[ postonly ] [ domain <domain> ]*
@ -378,7 +348,7 @@ public class HAProxyConfigurator implements LoadBalancerConfigurator {
for(Pair<String,String> paramKV :paramsList){
String key = paramKV.first();
String value = paramKV.second();
if ("name".equalsIgnoreCase(key)) name = value;
if ("cookie-name".equalsIgnoreCase(key)) name = value;
if ("mode".equalsIgnoreCase(key)) mode = value;
if ("domain".equalsIgnoreCase(key)) {
if (domainSb == null) {
@ -417,14 +387,6 @@ public class HAProxyConfigurator implements LoadBalancerConfigurator {
if ("tablesize".equalsIgnoreCase(key)) tablesize = value;
if ("expire".equalsIgnoreCase(key)) expire = value;
}
if ((expire != null) && !containsOnlyNumbers(expire, timeEndChar)) {
s_logger.warn("Haproxy stickiness policy for lb rule: " + lbTO.getSrcIp() + ":" + lbTO.getSrcPort() +": Not Applied, cause: expire is not in timeformat:" + expire);
return null;
}
if ((tablesize != null) && !containsOnlyNumbers(tablesize, "kmg")) {
s_logger.warn("Haproxy stickiness policy for lb rule: " + lbTO.getSrcIp() + ":" + lbTO.getSrcPort() +": Not Applied, cause: tablesize is not in size format:" + tablesize);
return null;
}
sb.append("\t").append("stick-table type ip size ")
.append(tablesize).append(" expire ").append(expire);
sb.append("\n\t").append("stick on src");
@ -445,7 +407,7 @@ public class HAProxyConfigurator implements LoadBalancerConfigurator {
for(Pair<String,String> paramKV :paramsList){
String key = paramKV.first();
String value = paramKV.second();
if ("name".equalsIgnoreCase(key)) name = value;
if ("cookie-name".equalsIgnoreCase(key)) name = value;
if ("length".equalsIgnoreCase(key)) length = value;
if ("holdtime".equalsIgnoreCase(key)) holdtime = value;
if ("mode".equalsIgnoreCase(key)) mode = value;
@ -461,14 +423,7 @@ public class HAProxyConfigurator implements LoadBalancerConfigurator {
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 (!containsOnlyNumbers(length, null)) {
s_logger.warn("Haproxy stickiness policy for lb rule: " + lbTO.getSrcIp() + ":" + lbTO.getSrcPort() +": Not Applied, cause: length is not a number:" + length);
return null;
}
if (!containsOnlyNumbers(holdtime, timeEndChar)) {
s_logger.warn("Haproxy stickiness policy for lb rule: " + lbTO.getSrcIp() + ":" + lbTO.getSrcPort() +": Not Applied, cause: holdtime is not in timeformat:" + holdtime);
return null;
}
sb.append("\t").append("appsession ").append(name)
.append(" len ").append(length).append(" timeout ")
.append(holdtime).append(" ");

View File

@ -0,0 +1,31 @@
/**
* Copyright (C) 2011 Citrix Systems, Inc. All rights reserved
*
* This software is licensed under the GNU General Public License v3 or later.
*
* It is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.cloud.network;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.network.lb.LoadBalancingRule;
public interface LoadBalancerValidator {
/**
* Validate rules
* @param rule
* @return true/false. If there are no validation then true should be return.
* @throws ResourceUnavailableException
*/
public boolean validateLBRule(LoadBalancingRule rule);
}

View File

@ -35,6 +35,7 @@ import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.InsufficientAddressCapacityException;
import com.cloud.exception.InsufficientCapacityException;
import com.cloud.exception.InsufficientVirtualNetworkCapcityException;
import com.cloud.exception.InvalidParameterValueException;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.hypervisor.Hypervisor.HypervisorType;
import com.cloud.network.Network.Capability;
@ -143,6 +144,8 @@ public interface NetworkManager extends NetworkService {
String getNextAvailableMacAddressInNetwork(long networkConfigurationId) throws InsufficientAddressCapacityException;
boolean applyRules(List<? extends FirewallRule> rules, boolean continueOnError) throws ResourceUnavailableException;
public boolean validateRule(FirewallRule rule);
List<? extends RemoteAccessVPNServiceProvider> getRemoteAccessVpnElements();

View File

@ -2947,6 +2947,28 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
return result;
}
@Override
public boolean validateRule(FirewallRule rule) {
Network network = _networksDao.findById(rule.getNetworkId());
Purpose purpose = rule.getPurpose();
for (NetworkElement ne : _networkElements) {
boolean validated;
switch (purpose) {
case LoadBalancing:
if (!(ne instanceof LoadBalancingServiceProvider)) {
continue;
}
validated = ((LoadBalancingServiceProvider) ne).validateLBRule(network, (LoadBalancingRule) rule);
if (!validated)
return false;
break;
default:
s_logger.debug("Unable to validate network rules for purpose: " + purpose.toString());
validated = false;
}
}
return true;
}
@Override
/* The rules here is only the same kind of rule, e.g. all load balancing rules or all port forwarding rules */
public boolean applyRules(List<? extends FirewallRule> rules, boolean continueOnError) throws ResourceUnavailableException {

View File

@ -32,6 +32,7 @@ import com.cloud.configuration.dao.ConfigurationDao;
import com.cloud.deploy.DeployDestination;
import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.InsufficientCapacityException;
import com.cloud.exception.InvalidParameterValueException;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.network.Network;
import com.cloud.network.Network.Capability;
@ -130,7 +131,12 @@ public class ElasticLoadBalancerElement extends AdapterBase implements LoadBalan
// TODO kill all loadbalancer vms by calling the ElasticLoadBalancerManager
return false;
}
@Override
public boolean validateLBRule(Network network, LoadBalancingRule rule) {
return true;
}
@Override
public boolean applyLBRules(Network network, List<LoadBalancingRule> rules) throws ResourceUnavailableException {
if (!canHandle(network)) {

View File

@ -158,6 +158,11 @@ public class F5ExternalLoadBalancerElement extends ExternalLoadBalancerDeviceMan
return true;
}
@Override
public boolean validateLBRule(Network network, LoadBalancingRule rule) {
return true;
}
@Override
public boolean applyLBRules(Network config, List<LoadBalancingRule> rules) throws ResourceUnavailableException {
if (!canHandle(config)) {

View File

@ -185,7 +185,12 @@ public class NetscalerElement extends ExternalLoadBalancerDeviceManagerImpl impl
public boolean destroy(Network config) {
return true;
}
@Override
public boolean validateLBRule(Network network, LoadBalancingRule rule) {
return true;
}
@Override
public boolean applyLBRules(Network config, List<LoadBalancingRule> rules) throws ResourceUnavailableException {
if (!canHandle(config, Service.Lb)) {

View File

@ -35,6 +35,7 @@ import com.cloud.dc.DataCenter.NetworkType;
import com.cloud.deploy.DeployDestination;
import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.InsufficientCapacityException;
import com.cloud.exception.InvalidParameterValueException;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.host.dao.HostDao;
import com.cloud.network.Network;
@ -54,6 +55,7 @@ import com.cloud.network.dao.NetworkDao;
import com.cloud.network.dao.VirtualRouterProviderDao;
import com.cloud.network.lb.LoadBalancingRule;
import com.cloud.network.lb.LoadBalancingRulesManager;
import com.cloud.network.lb.LoadBalancingRule.LbStickinessPolicy;
import com.cloud.network.router.VirtualNetworkApplianceManager;
import com.cloud.network.router.VirtualRouter;
import com.cloud.network.rules.LbStickinessMethod;
@ -68,6 +70,7 @@ import com.cloud.offerings.NetworkOfferingVO;
import com.cloud.offerings.dao.NetworkOfferingDao;
import com.cloud.user.AccountManager;
import com.cloud.uservm.UserVm;
import com.cloud.utils.Pair;
import com.cloud.utils.component.AdapterBase;
import com.cloud.utils.component.Inject;
import com.cloud.utils.db.SearchCriteria.Op;
@ -85,6 +88,7 @@ import com.cloud.vm.dao.DomainRouterDao;
import com.cloud.vm.dao.UserVmDao;
import com.google.gson.Gson;
@Local(value=NetworkElement.class)
public class VirtualRouterElement extends AdapterBase implements VirtualRouterElementService, DhcpServiceProvider, UserDataServiceProvider, SourceNatServiceProvider, StaticNatServiceProvider, FirewallServiceProvider, LoadBalancingServiceProvider, PortForwardingServiceProvider, RemoteAccessVPNServiceProvider, IpDeployer {
private static final Logger s_logger = Logger.getLogger(VirtualRouterElement.class);
@ -192,6 +196,114 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
return true;
}
}
/*
* This function detects numbers like 12 ,32h ,42m .. etc,. 1) plain
* number like 12 2) time or tablesize like 12h, 34m, 45k, 54m , here
* last character is non-digit but from known characters .
*/
private boolean containsOnlyNumbers(String str, String endChar) {
if (str == null)
return false;
String number = str;
if (endChar != null) {
boolean matchedEndChar = false;
if (str.length() < 2)
return false; // atleast one numeric and one char. example:
// 3h
char strEnd = str.toCharArray()[str.length() - 1];
for (char c : endChar.toCharArray()) {
if (strEnd == c) {
number = str.substring(0, str.length() - 1);
matchedEndChar = true;
break;
}
}
if (!matchedEndChar)
return false;
}
try {
int i = Integer.parseInt(number);
} catch (NumberFormatException e) {
return false;
}
return true;
}
private boolean validateHAProxyLBRule(LoadBalancingRule rule) {
String timeEndChar = "dhms";
for (LbStickinessPolicy stickinessPolicy : rule.getStickinessPolicies()) {
List<Pair<String, String>> paramsList = stickinessPolicy.getParams();
if (StickinessMethodType.LBCookieBased.getName().equalsIgnoreCase(stickinessPolicy.getMethodName())) {
} else if (StickinessMethodType.SourceBased.getName().equalsIgnoreCase(stickinessPolicy.getMethodName())) {
String tablesize = "200k"; // optional
String expire = "30m"; // optional
/* overwrite default values with the stick parameters */
for (Pair<String, String> paramKV : paramsList) {
String key = paramKV.first();
String value = paramKV.second();
if ("tablesize".equalsIgnoreCase(key))
tablesize = value;
if ("expire".equalsIgnoreCase(key))
expire = value;
}
if ((expire != null) && !containsOnlyNumbers(expire, timeEndChar)) {
throw new InvalidParameterValueException("Failed LB in validation rule id: " + rule.getId() + " Cause: expire is not in timeformat: " + expire);
}
if ((tablesize != null) && !containsOnlyNumbers(tablesize, "kmg")) {
throw new InvalidParameterValueException("Failed LB in validation rule id: " + rule.getId() + " Cause: tablesize is not in size format: " + tablesize);
}
} else if (StickinessMethodType.AppCookieBased.getName().equalsIgnoreCase(stickinessPolicy.getMethodName())) {
/*
* FORMAT : appsession <cookie> len <length> timeout <holdtime>
* [request-learn] [prefix] [mode
* <path-parameters|query-string>]
*/
/* example: appsession JSESSIONID len 52 timeout 3h */
String cookieName = null; // required
String length = null; // required
String holdTime = null; // required
for (Pair<String, String> paramKV : paramsList) {
String key = paramKV.first();
String value = paramKV.second();
if ("cookie-name".equalsIgnoreCase(key))
cookieName = value;
if ("length".equalsIgnoreCase(key))
length = value;
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)) {
throw new InvalidParameterValueException("Failed LB in validation rule id: " + rule.getId() + " Cause: length is not a number: " + length);
}
if (!containsOnlyNumbers(holdTime, timeEndChar)) {
throw new InvalidParameterValueException("Failed LB in validation rule id: " + rule.getId() + " Cause: holdtime is not in timeformat: " + holdTime);
}
}
}
return true;
}
@Override
public boolean validateLBRule(Network network, LoadBalancingRule rule) {
if (canHandle(network, Service.Lb)) {
List<DomainRouterVO> routers = _routerDao.listByNetworkAndRole(network.getId(), Role.VIRTUAL_ROUTER);
if (routers == null || routers.isEmpty()) {
return true;
}
return validateHAProxyLBRule(rule);
}
return true;
}
@Override
public boolean applyLBRules(Network network, List<LoadBalancingRule> rules) throws ResourceUnavailableException {
@ -292,6 +404,37 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
return capabilities;
}
private static String getHAProxyStickinessCapability() {
LbStickinessMethod method;
List <LbStickinessMethod> methodList = new ArrayList<LbStickinessMethod>(1);
method = new LbStickinessMethod(StickinessMethodType.LBCookieBased, "This is loadbalancer cookie based stickiness method.");
method.addParam("cookie-name", false, "Cookie name passed in http header by the LB to the client.", false);
method.addParam("mode", false, "Valid values: insert, rewrite, prefix. Default value: insert. In the insert mode cookie will be created by the LB. In other modes, cookie will be created by the server and LB modifies it.", false);
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.", 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");
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("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);
method.addParam("request-learn", false, "If this option is specified, then haproxy will be able to learn the cookie found in the request in case the server does not specify any in response. This is typically what happens with PHPSESSID cookies, or when haproxy's session expires before the application's session and the correct server is selected. It is recommended to specify this option to improve reliability", true);
method.addParam("prefix", false, "When this option is specified, haproxy will match on the cookie prefix (or URL parameter prefix). The appsession value is the data following this prefix. Example : appsession ASPSESSIONID len 64 timeout 3h prefix This will match the cookie ASPSESSIONIDXXXX=XXXXX, the appsession value will be XXXX=XXXXX.", true);
method.addParam("mode", false, "This option allows to change the URL parser mode. 2 modes are currently supported : - path-parameters : The parser looks for the appsession in the path parameters part (each parameter is separated by a semi-colon), which is convenient for JSESSIONID for example.This is the default mode if the option is not set. - query-string : In this mode, the parser will look for the appsession in the query string.", false);
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);
methodList.add(method);
Gson gson = new Gson();
String capability = gson.toJson(methodList);
return capability;
}
private static Map<Service, Map<Capability, String>> setCapabilities() {
Map<Service, Map<Capability, String>> capabilities = new HashMap<Service, Map<Capability, String>>();
@ -301,35 +444,7 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
lbCapabilities.put(Capability.SupportedLBIsolation, "dedicated");
lbCapabilities.put(Capability.SupportedProtocols, "tcp, udp");
LbStickinessMethod method;
List <LbStickinessMethod> methodList = new ArrayList<LbStickinessMethod>(1);
method = new LbStickinessMethod(StickinessMethodType.LBCookieBased,"This is loadbalancer cookie based stickiness method.");
method.addParam("name", false, "Cookie name passed in http header by the LB to the client.",false);
method.addParam("mode", false, "valid value : insert ,rewrite/prefix . default value: insert, In the insert mode cookie will be created by the LB . in other mode cookie will be created by the server and LB modifies it.",false);
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.",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");
method.addParam("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("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);
method.addParam("request-learn", false, "If this option is specified, then haproxy will be able to learn the cookie found in the request in case the server does not specify any in response. This is typically what happens with PHPSESSID cookies, or when haproxy's session expires before the application's session and the correct server is selected. It is recommended to specify this option to improve reliability",true);
method.addParam("prefix", false,"When this option is specified, haproxy will match on the cookie prefix (or URL parameter prefix). The appsession value is the data following this prefix. Example : appsession ASPSESSIONID len 64 timeout 3h prefix This will match the cookie ASPSESSIONIDXXXX=XXXXX, the appsession value will be XXXX=XXXXX.",true);
method.addParam("mode", false,"This option allows to change the URL parser mode. 2 modes are currently supported : - path-parameters : The parser looks for the appsession in the path parameters part (each parameter is separated by a semi-colon), which is convenient for JSESSIONID for example.This is the default mode if the option is not set. - query-string : In this mode, the parser will look for the appsession in the query string.",false);
methodList.add(method);
method = new LbStickinessMethod(StickinessMethodType.SourceBased,"This is source based sticky 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 , combinations is not valid",false);
methodList.add(method);
Gson gson = new Gson();
String s = gson.toJson(methodList);
s_logger.info("Before Converting to : " + s);
lbCapabilities.put(Capability.SupportedStickinessMethods,s);
lbCapabilities.put(Capability.SupportedStickinessMethods, getHAProxyStickinessCapability());
capabilities.put(Service.Lb, lbCapabilities);

View File

@ -181,23 +181,8 @@ public class LoadBalancingRulesManagerImpl<Type> implements LoadBalancingRulesMa
return null;
}
@SuppressWarnings("rawtypes")
@Override
@DB
@ActionEvent(eventType = EventTypes.EVENT_LB_STICKINESSPOLICY_CREATE, eventDescription = "create lb stickinesspolicy to load balancer", create = true)
public StickinessPolicy createLBStickinessPolicy(CreateLBStickinessPolicyCmd cmd) throws NetworkRuleConflictException {
UserContext caller = UserContext.current();
/* Validation : check corresponding load balancer rule exist */
private boolean genericValidator(CreateLBStickinessPolicyCmd cmd) throws InvalidParameterValueException {
LoadBalancerVO loadBalancer = _lbDao.findById(cmd.getLbRuleId());
if (loadBalancer == null) {
throw new InvalidParameterValueException("Failed: LB rule id: " + cmd.getLbRuleId() + " not present ");
}
_accountMgr.checkAccess(caller.getCaller(), null, true, loadBalancer);
if (loadBalancer.getState() == FirewallRule.State.Revoke) {
throw new InvalidParameterValueException("Failed: LB rule id:" + cmd.getLbRuleId() + " is in deleting state: ");
}
/* Validation : check for valid Method name and params */
List<LbStickinessMethod> stickinessMethodList = getStickinessMethods(loadBalancer
.getNetworkId());
@ -258,15 +243,48 @@ public class LoadBalancingRulesManagerImpl<Type> implements LoadBalancingRulesMa
if (methodMatch == false) {
throw new InvalidParameterValueException("Failed to match Stickiness method name for LB rule:" + cmd.getLbRuleId());
}
/* Validation : check for the multiple policies to the rule id */
List<LBStickinessPolicyVO> stickinessPolicies = _lb2stickinesspoliciesDao.listByLoadBalancerId(cmd.getLbRuleId(), false);
if (stickinessPolicies.size() > 0) {
throw new InvalidParameterValueException("Failed to create Stickiness policy: Already policy attached " + cmd.getLbRuleId());
}
return true;
}
@SuppressWarnings("rawtypes")
@Override
@DB
@ActionEvent(eventType = EventTypes.EVENT_LB_STICKINESSPOLICY_CREATE, eventDescription = "create lb stickinesspolicy to load balancer", create = true)
public StickinessPolicy createLBStickinessPolicy(CreateLBStickinessPolicyCmd cmd) throws NetworkRuleConflictException {
UserContext caller = UserContext.current();
/* Validation : check corresponding load balancer rule exist */
LoadBalancerVO loadBalancer = _lbDao.findById(cmd.getLbRuleId());
if (loadBalancer == null) {
throw new InvalidParameterValueException("Failed: LB rule id: " + cmd.getLbRuleId() + " not present ");
}
_accountMgr.checkAccess(caller.getCaller(), null, true, loadBalancer);
if (loadBalancer.getState() == FirewallRule.State.Revoke) {
throw new InvalidParameterValueException("Failed: LB rule id:" + cmd.getLbRuleId() + " is in deleting state: ");
}
/* Generic validations */
if (!genericValidator(cmd)) {
throw new InvalidParameterValueException("Failed to create Stickiness policy: Validation Failed " + cmd.getLbRuleId());
}
/* Specific validations using network element validator for specific validations*/
LBStickinessPolicyVO lbpolicy = new LBStickinessPolicyVO(loadBalancer.getId(), cmd.getLBStickinessPolicyName(), cmd.getStickinessMethodName(), cmd.getparamList(), cmd.getDescription());
List<LbStickinessPolicy> policyList = new ArrayList<LbStickinessPolicy>();
policyList.add(new LbStickinessPolicy(cmd.getStickinessMethodName(), lbpolicy.getParams()));
LoadBalancingRule lbRule = new LoadBalancingRule(loadBalancer, getExistingDestinations(lbpolicy.getId()), policyList);
if (!_networkMgr.validateRule(lbRule)) {
throw new InvalidParameterValueException("Failed to create Stickiness policy: Validation Failed " + cmd.getLbRuleId());
}
/* Finally Insert into DB */
LBStickinessPolicyVO policy = new LBStickinessPolicyVO(loadBalancer.getId(), cmd.getLBStickinessPolicyName(), cmd.getStickinessMethodName(), cmd.getparamList(), cmd.getDescription());
policy = _lb2stickinesspoliciesDao.persist(policy);