Search in sources :

Example 1 with LoadBalancer

use of com.cloud.network.rules.LoadBalancer in project CloudStack-archive by CloudStack-extras.

the class UpdateLoadBalancerRuleCmd method execute.

@Override
public void execute() {
    UserContext.current().setEventDetails("Load balancer Id: " + getId());
    LoadBalancer result = _lbService.updateLoadBalancerRule(this);
    if (result != null) {
        LoadBalancerResponse response = _responseGenerator.createLoadBalancerResponse(result);
        response.setResponseName(getCommandName());
        this.setResponseObject(response);
    } else {
        throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to update load balancer rule");
    }
}
Also used : LoadBalancerResponse(com.cloud.api.response.LoadBalancerResponse) ServerApiException(com.cloud.api.ServerApiException) LoadBalancer(com.cloud.network.rules.LoadBalancer)

Example 2 with LoadBalancer

use of com.cloud.network.rules.LoadBalancer in project CloudStack-archive by CloudStack-extras.

the class ListLoadBalancerRulesCmd method execute.

@Override
public void execute() {
    List<? extends LoadBalancer> loadBalancers = _lbService.searchForLoadBalancers(this);
    ListResponse<LoadBalancerResponse> response = new ListResponse<LoadBalancerResponse>();
    List<LoadBalancerResponse> lbResponses = new ArrayList<LoadBalancerResponse>();
    if (loadBalancers != null) {
        for (LoadBalancer loadBalancer : loadBalancers) {
            LoadBalancerResponse lbResponse = _responseGenerator.createLoadBalancerResponse(loadBalancer);
            lbResponse.setObjectName("loadbalancerrule");
            lbResponses.add(lbResponse);
        }
    }
    response.setResponses(lbResponses);
    response.setResponseName(getCommandName());
    this.setResponseObject(response);
}
Also used : LoadBalancerResponse(com.cloud.api.response.LoadBalancerResponse) ListResponse(com.cloud.api.response.ListResponse) ArrayList(java.util.ArrayList) LoadBalancer(com.cloud.network.rules.LoadBalancer)

Example 3 with LoadBalancer

use of com.cloud.network.rules.LoadBalancer in project CloudStack-archive by CloudStack-extras.

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.createLoadBalancerRule(this, getOpenFirewall());
        this.setEntityId(result.getId());
    } catch (NetworkRuleConflictException e) {
        s_logger.warn("Exception: ", e);
        throw new ServerApiException(BaseCmd.NETWORK_RULE_CONFLICT_ERROR, e.getMessage());
    } catch (InsufficientAddressCapacityException e) {
        s_logger.warn("Exception: ", e);
        throw new ServerApiException(BaseCmd.INSUFFICIENT_CAPACITY_ERROR, e.getMessage());
    }
}
Also used : ServerApiException(com.cloud.api.ServerApiException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) InsufficientAddressCapacityException(com.cloud.exception.InsufficientAddressCapacityException) LoadBalancer(com.cloud.network.rules.LoadBalancer) NetworkRuleConflictException(com.cloud.exception.NetworkRuleConflictException)

Example 4 with LoadBalancer

use of com.cloud.network.rules.LoadBalancer in project CloudStack-archive by CloudStack-extras.

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 5 with LoadBalancer

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

the class ListLBHealthCheckPoliciesCmd method execute.

@Override
public void execute() {
    List<LBHealthCheckResponse> hcpResponses = new ArrayList<LBHealthCheckResponse>();
    ListResponse<LBHealthCheckResponse> response = new ListResponse<LBHealthCheckResponse>();
    Long lbRuleId = getLbRuleId();
    Long hId = getId();
    if (lbRuleId == null) {
        if (hId != null) {
            lbRuleId = _lbService.findLBIdByHealtCheckPolicyId(hId);
        } else {
            throw new InvalidParameterValueException("Either load balancer rule ID or health check policy ID should be specified");
        }
    }
    LoadBalancer lb = _lbService.findById(lbRuleId);
    if (lb != null) {
        List<? extends HealthCheckPolicy> healthCheckPolicies = _lbService.searchForLBHealthCheckPolicies(this);
        LBHealthCheckResponse spResponse = _responseGenerator.createLBHealthCheckPolicyResponse(healthCheckPolicies, lb);
        hcpResponses.add(spResponse);
        response.setResponses(hcpResponses);
    }
    response.setResponseName(getCommandName());
    this.setResponseObject(response);
}
Also used : ListResponse(org.apache.cloudstack.api.response.ListResponse) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) ArrayList(java.util.ArrayList) LoadBalancer(com.cloud.network.rules.LoadBalancer) LBHealthCheckResponse(org.apache.cloudstack.api.response.LBHealthCheckResponse)

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