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");
}
}
}
use of com.cloud.network.rules.LoadBalancer in project cloudstack by apache.
the class DeleteLBStickinessPolicyCmd method getSyncObjId.
@Override
public Long getSyncObjId() {
StickinessPolicy policy = _entityMgr.findById(StickinessPolicy.class, getId());
if (policy == null) {
throw new InvalidParameterValueException("Unable to find LB stickiness rule: " + id);
}
LoadBalancer lb = _lbService.findById(policy.getLoadBalancerId());
if (lb == null) {
throw new InvalidParameterValueException("Unable to find load balancer rule for stickiness rule: " + id);
}
return lb.getNetworkId();
}
use of com.cloud.network.rules.LoadBalancer in project cloudstack by apache.
the class UpdateLBHealthCheckPolicyCmd method execute.
/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
@Override
public void execute() {
HealthCheckPolicy policy = _lbService.updateLBHealthCheckPolicy(this.getId(), this.getCustomId(), this.getDisplay());
LoadBalancer lb = _lbService.findById(policy.getLoadBalancerId());
LBHealthCheckResponse hcResponse = _responseGenerator.createLBHealthCheckPolicyResponse(policy, lb);
setResponseObject(hcResponse);
hcResponse.setResponseName(getCommandName());
}
Aggregations