} else {
throw new ExecutionException("Got invalid load balancing algorithm: " + lbAlgorithm + " in the load balancing rule");
}
boolean vserverExisis = false;
lbvserver vserver = getVirtualServerIfExisits(virtualServerName);
if (vserver != null) {
if (!vserver.get_servicetype().equalsIgnoreCase(protocol)) {
throw new ExecutionException("Can not update virtual server:" + virtualServerName + " as current protocol:" + vserver.get_servicetype() +
" of virtual server is different from the " + " intended protocol:" + protocol);
}
vserverExisis = true;
}
// Use new vserver always for configuration
vserver = new lbvserver();
vserver.set_name(virtualServerName);
vserver.set_ipv46(publicIp);
vserver.set_port(publicPort);
vserver.set_servicetype(protocol);
vserver.set_lbmethod(lbMethod);
// netmask can only be set for source IP load balancer algorithm
if (!lbMethod.equalsIgnoreCase("SOURCEIPHASH")) {
vserver.set_netmask(null);
vserver.set_v6netmasklen(null);
}
if ((stickyPolicies != null) && (stickyPolicies.length > 0) && (stickyPolicies[0] != null)) {
long timeout = 2;// netscaler default 2 min
String cookieName = null;
StickinessPolicyTO stickinessPolicy = stickyPolicies[0];
// get the session persistence parameters
List<Pair<String, String>> paramsList = stickinessPolicy.getParams();
for (Pair<String, String> param : paramsList) {
if ("holdtime".equalsIgnoreCase(param.first())) {
timeout = Long.parseLong(param.second());
} else if ("name".equalsIgnoreCase(param.first())) {
cookieName = param.second();
}
}
// configure virtual server based on the persistence method
if (StickinessMethodType.LBCookieBased.getName().equalsIgnoreCase(stickinessPolicy.getMethodName())) {
vserver.set_persistencetype("COOKIEINSERT");
} else if (StickinessMethodType.SourceBased.getName().equalsIgnoreCase(stickinessPolicy.getMethodName())) {
vserver.set_persistencetype("SOURCEIP");
} else if (StickinessMethodType.AppCookieBased.getName().equalsIgnoreCase(stickinessPolicy.getMethodName())) {
vserver.set_persistencetype("RULE");
vserver.set_rule("HTTP.REQ.HEADER(\"COOKIE\").VALUE(0).typecast_nvlist_t('=',';').value(\"" + cookieName + "\")");
vserver.set_resrule("HTTP.RES.HEADER(\"SET-COOKIE\").VALUE(0).typecast_nvlist_t('=',';').value(\"" + cookieName + "\")");
} else {
throw new ExecutionException("Got invalid session persistence method: " + stickinessPolicy.getMethodName() + " in the load balancing rule");
}
// set session persistence timeout
vserver.set_timeout(timeout);
} else {
// delete the LB stickyness policy
vserver.set_persistencetype("NONE");
}
if (vserverExisis) {
apiCallResult = lbvserver.update(_netscalerService, vserver);
} else {