Search in sources :

Example 16 with LoadBalancer

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);
}
Also used : Account(com.cloud.user.Account) ListResponse(com.cloud.api.response.ListResponse) ArrayList(java.util.ArrayList) LoadBalancer(com.cloud.network.rules.LoadBalancer) LBStickinessResponse(com.cloud.api.response.LBStickinessResponse)

Example 17 with LoadBalancer

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;
}
Also used : HashMap(java.util.HashMap) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) Iterator(java.util.Iterator) Collection(java.util.Collection) LoadBalancer(com.cloud.network.rules.LoadBalancer)

Example 18 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 19 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 20 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)

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