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;
}
Aggregations