Search in sources :

Example 21 with LoadBalancer

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);
}
Also used : LoadBalancerResponse(org.apache.cloudstack.api.response.LoadBalancerResponse) ListResponse(org.apache.cloudstack.api.response.ListResponse) ArrayList(java.util.ArrayList) LoadBalancer(com.cloud.network.rules.LoadBalancer) ArrayList(java.util.ArrayList) List(java.util.List)

Example 22 with LoadBalancer

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());
    }
}
Also used : ServerApiException(org.apache.cloudstack.api.ServerApiException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) InsufficientAddressCapacityException(com.cloud.exception.InsufficientAddressCapacityException) LoadBalancer(com.cloud.network.rules.LoadBalancer) NetworkRuleConflictException(com.cloud.exception.NetworkRuleConflictException)

Example 23 with LoadBalancer

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");
        }
    }
}
Also used : LoadBalancerResponse(org.apache.cloudstack.api.response.LoadBalancerResponse) ServerApiException(org.apache.cloudstack.api.ServerApiException) LoadBalancer(com.cloud.network.rules.LoadBalancer) CallContext(org.apache.cloudstack.context.CallContext) ServerApiException(org.apache.cloudstack.api.ServerApiException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) ResourceAllocationException(com.cloud.exception.ResourceAllocationException) NetworkRuleConflictException(com.cloud.exception.NetworkRuleConflictException) InsufficientAddressCapacityException(com.cloud.exception.InsufficientAddressCapacityException)

Example 24 with LoadBalancer

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();
}
Also used : InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) LoadBalancer(com.cloud.network.rules.LoadBalancer) StickinessPolicy(com.cloud.network.rules.StickinessPolicy)

Example 25 with LoadBalancer

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());
}
Also used : LoadBalancer(com.cloud.network.rules.LoadBalancer) LBHealthCheckResponse(org.apache.cloudstack.api.response.LBHealthCheckResponse) HealthCheckPolicy(com.cloud.network.rules.HealthCheckPolicy)

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