Search in sources :

Example 6 with LbStickinessMethod

use of com.cloud.network.rules.LbStickinessMethod in project cloudstack by apache.

the class LoadBalancingRulesManagerImpl method genericValidator.

private boolean genericValidator(CreateLBStickinessPolicyCmd cmd) throws InvalidParameterValueException {
    LoadBalancerVO loadBalancer = _lbDao.findById(cmd.getLbRuleId());
    /* Validation : check for valid Method name and params */
    List<LbStickinessMethod> stickinessMethodList = getStickinessMethods(loadBalancer.getNetworkId());
    boolean methodMatch = false;
    if (stickinessMethodList == null) {
        throw new InvalidParameterValueException("Failed:  No Stickiness method available for LB rule:" + cmd.getLbRuleId());
    }
    for (LbStickinessMethod method : stickinessMethodList) {
        if (method.getMethodName().equalsIgnoreCase(cmd.getStickinessMethodName())) {
            methodMatch = true;
            Map apiParamList = cmd.getparamList();
            List<LbStickinessMethodParam> methodParamList = method.getParamList();
            Map<String, String> tempParamList = new HashMap<String, String>();
            /*
                 * validation-1: check for any extra params that are not
                 * required by the policymethod(capability), FIXME: make the
                 * below loop simple without using raw data type
                 */
            if (apiParamList != null) {
                Collection userGroupCollection = apiParamList.values();
                Iterator iter = userGroupCollection.iterator();
                while (iter.hasNext()) {
                    HashMap<String, String> paramKVpair = (HashMap) iter.next();
                    String paramName = paramKVpair.get("name");
                    String paramValue = paramKVpair.get("value");
                    tempParamList.put(paramName, paramValue);
                    Boolean found = false;
                    for (LbStickinessMethodParam param : methodParamList) {
                        if (param.getParamName().equalsIgnoreCase(paramName)) {
                            if ((param.getIsflag() == false) && (paramValue == null)) {
                                throw new InvalidParameterValueException("Failed : Value expected for the Param :" + param.getParamName());
                            }
                            found = true;
                            break;
                        }
                    }
                    if (!found) {
                        throw new InvalidParameterValueException("Failed : Stickiness policy does not support param name :" + paramName);
                    }
                }
            }
            /* validation-2: check for mandatory params */
            for (LbStickinessMethodParam param : methodParamList) {
                if (param.getRequired()) {
                    if (tempParamList.get(param.getParamName()) == null) {
                        throw new InvalidParameterValueException("Failed : Missing Manadatory Param :" + param.getParamName());
                    }
                }
            }
            /* Successfully completed the Validation */
            break;
        }
    }
    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() > 1) {
        throw new InvalidParameterValueException("Failed to create Stickiness policy: Already two policies attached " + cmd.getLbRuleId());
    }
    return true;
}
Also used : HashMap(java.util.HashMap) LoadBalancerVO(com.cloud.network.dao.LoadBalancerVO) LBStickinessPolicyVO(com.cloud.network.dao.LBStickinessPolicyVO) LbStickinessMethod(com.cloud.network.rules.LbStickinessMethod) LbStickinessMethodParam(com.cloud.network.rules.LbStickinessMethod.LbStickinessMethodParam) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) Iterator(java.util.Iterator) Collection(java.util.Collection) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

LbStickinessMethod (com.cloud.network.rules.LbStickinessMethod)6 Gson (com.google.gson.Gson)5 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)3 Map (java.util.Map)3 Capability (com.cloud.network.Network.Capability)2 Service (com.cloud.network.Network.Service)2 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)1 AutoScaleCounter (com.cloud.network.as.AutoScaleCounter)1 LBStickinessPolicyVO (com.cloud.network.dao.LBStickinessPolicyVO)1 LoadBalancerVO (com.cloud.network.dao.LoadBalancerVO)1 LbStickinessMethodParam (com.cloud.network.rules.LbStickinessMethod.LbStickinessMethodParam)1 Collection (java.util.Collection)1 Iterator (java.util.Iterator)1 List (java.util.List)1