Search in sources :

Example 26 with LoadBalancer

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

the class AssignToGlobalLoadBalancerRuleCmd method getLoadBalancerRuleWeightMap.

public Map<Long, Long> getLoadBalancerRuleWeightMap() {
    Map<Long, Long> lbRuleWeightMap = new HashMap<Long, Long>();
    if (gslbLbRuleWieghtMap == null || gslbLbRuleWieghtMap.isEmpty()) {
        return null;
    }
    Collection lbruleWeightsCollection = gslbLbRuleWieghtMap.values();
    Iterator iter = lbruleWeightsCollection.iterator();
    while (iter.hasNext()) {
        HashMap<String, String> map = (HashMap<String, String>) iter.next();
        Long weight;
        LoadBalancer lbrule = _entityMgr.findByUuid(LoadBalancer.class, map.get("loadbalancerid"));
        if (lbrule == null) {
            throw new InvalidParameterValueException("Unable to find load balancer rule with ID: " + map.get("loadbalancerid"));
        }
        try {
            weight = Long.parseLong(map.get("weight"));
            if (weight < 1 || weight > 100) {
                throw new InvalidParameterValueException("Invalid weight " + weight + " given for the LB rule id: " + map.get("loadbalancerid"));
            }
        } catch (NumberFormatException nfe) {
            throw new InvalidParameterValueException("Unable to translate weight given for the LB rule id: " + map.get("loadbalancerid"));
        }
        lbRuleWeightMap.put(lbrule.getId(), weight);
    }
    return lbRuleWeightMap;
}
Also used : HashMap(java.util.HashMap) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) Iterator(java.util.Iterator) Collection(java.util.Collection) LoadBalancer(com.cloud.network.rules.LoadBalancer)

Aggregations

LoadBalancer (com.cloud.network.rules.LoadBalancer)26 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)12 ArrayList (java.util.ArrayList)9 NetworkRuleConflictException (com.cloud.exception.NetworkRuleConflictException)6 InsufficientAddressCapacityException (com.cloud.exception.InsufficientAddressCapacityException)5 StickinessPolicy (com.cloud.network.rules.StickinessPolicy)5 Account (com.cloud.user.Account)5 ServerApiException (org.apache.cloudstack.api.ServerApiException)5 ServerApiException (com.cloud.api.ServerApiException)4 LoadBalancerResponse (org.apache.cloudstack.api.response.LoadBalancerResponse)4 LoadBalancerResponse (com.cloud.api.response.LoadBalancerResponse)3 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)3 HealthCheckPolicy (com.cloud.network.rules.HealthCheckPolicy)3 LBHealthCheckResponse (org.apache.cloudstack.api.response.LBHealthCheckResponse)3 LBStickinessResponse (org.apache.cloudstack.api.response.LBStickinessResponse)3 ListResponse (org.apache.cloudstack.api.response.ListResponse)3 LBStickinessResponse (com.cloud.api.response.LBStickinessResponse)2 ListResponse (com.cloud.api.response.ListResponse)2 ResourceAllocationException (com.cloud.exception.ResourceAllocationException)2 Network (com.cloud.network.Network)2