use of com.cloud.network.rules.LoadBalancer in project CloudStack-archive by CloudStack-extras.
the class ListLBStickinessPoliciesCmd method execute.
@Override
public void execute() {
List<LBStickinessResponse> spResponses = new ArrayList<LBStickinessResponse>();
LoadBalancer lb = _lbService.findById(getLbRuleId());
ListResponse<LBStickinessResponse> response = new ListResponse<LBStickinessResponse>();
if (lb != null) {
//check permissions
Account caller = UserContext.current().getCaller();
_accountService.checkAccess(caller, null, true, lb);
List<? extends StickinessPolicy> stickinessPolicies = _lbService.searchForLBStickinessPolicies(this);
LBStickinessResponse spResponse = _responseGenerator.createLBStickinessPolicyResponse(stickinessPolicies, lb);
spResponses.add(spResponse);
response.setResponses(spResponses);
}
response.setResponseName(getCommandName());
this.setResponseObject(response);
}
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;
}
use of com.cloud.network.rules.LoadBalancer in project cloudstack by apache.
the class ListLoadBalancerRulesCmd method execute.
@Override
public void execute() {
Pair<List<? extends LoadBalancer>, Integer> loadBalancers = _lbService.searchForLoadBalancers(this);
ListResponse<LoadBalancerResponse> response = new ListResponse<LoadBalancerResponse>();
List<LoadBalancerResponse> lbResponses = new ArrayList<LoadBalancerResponse>();
if (loadBalancers != null) {
for (LoadBalancer loadBalancer : loadBalancers.first()) {
LoadBalancerResponse lbResponse = _responseGenerator.createLoadBalancerResponse(loadBalancer);
lbResponse.setObjectName("loadbalancerrule");
lbResponses.add(lbResponse);
}
response.setResponses(lbResponses, loadBalancers.second());
}
response.setResponseName(getCommandName());
this.setResponseObject(response);
}
use of com.cloud.network.rules.LoadBalancer in project cloudstack by apache.
the class CreateLoadBalancerRuleCmd method create.
@Override
public void create() {
//cidr list parameter is deprecated
if (cidrlist != null) {
throw new InvalidParameterValueException("Parameter cidrList is deprecated; if you need to open firewall rule for the specific CIDR, please refer to createFirewallRule command");
}
try {
LoadBalancer result = _lbService.createPublicLoadBalancerRule(getXid(), getName(), getDescription(), getSourcePortStart(), getSourcePortEnd(), getDefaultPortStart(), getDefaultPortEnd(), getSourceIpAddressId(), getProtocol(), getAlgorithm(), getNetworkId(), getEntityOwnerId(), getOpenFirewall(), getLbProtocol(), isDisplay());
this.setEntityId(result.getId());
this.setEntityUuid(result.getUuid());
} catch (NetworkRuleConflictException e) {
s_logger.warn("Exception: ", e);
throw new ServerApiException(ApiErrorCode.NETWORK_RULE_CONFLICT_ERROR, e.getMessage());
} catch (InsufficientAddressCapacityException e) {
s_logger.warn("Exception: ", e);
throw new ServerApiException(ApiErrorCode.INSUFFICIENT_CAPACITY_ERROR, e.getMessage());
} catch (InvalidParameterValueException e) {
throw new ServerApiException(ApiErrorCode.PARAM_ERROR, e.getMessage());
}
}
use of com.cloud.network.rules.LoadBalancer in project cloudstack by apache.
the class CreateLoadBalancerRuleCmd method execute.
@Override
public void execute() throws ResourceAllocationException, ResourceUnavailableException {
CallContext callerContext = CallContext.current();
boolean success = true;
LoadBalancer rule = null;
try {
CallContext.current().setEventDetails("Rule Id: " + getEntityId());
if (getOpenFirewall()) {
success = success && _firewallService.applyIngressFirewallRules(getSourceIpAddressId(), callerContext.getCallingAccount());
}
// State might be different after the rule is applied, so get new object here
rule = _entityMgr.findById(LoadBalancer.class, getEntityId());
LoadBalancerResponse lbResponse = new LoadBalancerResponse();
if (rule != null) {
lbResponse = _responseGenerator.createLoadBalancerResponse(rule);
setResponseObject(lbResponse);
}
lbResponse.setResponseName(getCommandName());
} catch (Exception ex) {
s_logger.warn("Failed to create LB rule due to exception ", ex);
} finally {
if (!success || rule == null) {
if (getOpenFirewall()) {
_firewallService.revokeRelatedFirewallRule(getEntityId(), true);
}
// no need to apply the rule on the backend as it exists in the db only
_lbService.deleteLoadBalancerRule(getEntityId(), false);
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create load balancer rule");
}
}
}
Aggregations