Search in sources :

Example 1 with ApplicationLoadBalancerRule

use of org.apache.cloudstack.network.lb.ApplicationLoadBalancerRule in project cloudstack by apache.

the class CreateApplicationLoadBalancerCmd method create.

@Override
public void create() {
    try {
        ApplicationLoadBalancerRule result = _appLbService.createApplicationLoadBalancer(getName(), getDescription(), getScheme(), getSourceIpNetworkId(), getSourceIp(), getSourcePort(), getInstancePort(), getAlgorithm(), getNetworkId(), getEntityOwnerId(), getDisplay());
        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 (InsufficientVirtualNetworkCapacityException e) {
        s_logger.warn("Exception: ", e);
        throw new ServerApiException(ApiErrorCode.INSUFFICIENT_CAPACITY_ERROR, e.getMessage());
    }
}
Also used : ServerApiException(org.apache.cloudstack.api.ServerApiException) InsufficientAddressCapacityException(com.cloud.exception.InsufficientAddressCapacityException) InsufficientVirtualNetworkCapacityException(com.cloud.exception.InsufficientVirtualNetworkCapacityException) ApplicationLoadBalancerRule(org.apache.cloudstack.network.lb.ApplicationLoadBalancerRule) NetworkRuleConflictException(com.cloud.exception.NetworkRuleConflictException)

Example 2 with ApplicationLoadBalancerRule

use of org.apache.cloudstack.network.lb.ApplicationLoadBalancerRule in project cloudstack by apache.

the class CreateApplicationLoadBalancerCmd method execute.

@Override
public void execute() throws ResourceAllocationException, ResourceUnavailableException {
    ApplicationLoadBalancerRule rule = null;
    try {
        CallContext.current().setEventDetails("Load Balancer Id: " + getEntityId());
        // State might be different after the rule is applied, so get new object here
        rule = _entityMgr.findById(ApplicationLoadBalancerRule.class, getEntityId());
        ApplicationLoadBalancerResponse lbResponse = _responseGenerator.createLoadBalancerContainerReponse(rule, _lbService.getLbInstances(getEntityId()));
        setResponseObject(lbResponse);
        lbResponse.setResponseName(getCommandName());
    } catch (Exception ex) {
        s_logger.warn("Failed to create load balancer due to exception ", ex);
    } finally {
        if (rule == null) {
            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create load balancer");
        }
    }
}
Also used : ServerApiException(org.apache.cloudstack.api.ServerApiException) ApplicationLoadBalancerRule(org.apache.cloudstack.network.lb.ApplicationLoadBalancerRule) ApplicationLoadBalancerResponse(org.apache.cloudstack.api.response.ApplicationLoadBalancerResponse) ServerApiException(org.apache.cloudstack.api.ServerApiException) NetworkRuleConflictException(com.cloud.exception.NetworkRuleConflictException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) ResourceAllocationException(com.cloud.exception.ResourceAllocationException) InsufficientAddressCapacityException(com.cloud.exception.InsufficientAddressCapacityException) InsufficientVirtualNetworkCapacityException(com.cloud.exception.InsufficientVirtualNetworkCapacityException)

Example 3 with ApplicationLoadBalancerRule

use of org.apache.cloudstack.network.lb.ApplicationLoadBalancerRule in project cloudstack by apache.

the class ListApplicationLoadBalancersCmd method execute.

// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////
@Override
public void execute() {
    Pair<List<? extends ApplicationLoadBalancerRule>, Integer> loadBalancers = _appLbService.listApplicationLoadBalancers(this);
    ListResponse<ApplicationLoadBalancerResponse> response = new ListResponse<ApplicationLoadBalancerResponse>();
    List<ApplicationLoadBalancerResponse> lbResponses = new ArrayList<ApplicationLoadBalancerResponse>();
    for (ApplicationLoadBalancerRule loadBalancer : loadBalancers.first()) {
        ApplicationLoadBalancerResponse lbResponse = _responseGenerator.createLoadBalancerContainerReponse(loadBalancer, _lbService.getLbInstances(loadBalancer.getId()));
        lbResponse.setObjectName("loadbalancer");
        lbResponses.add(lbResponse);
    }
    response.setResponses(lbResponses, loadBalancers.second());
    response.setResponseName(getCommandName());
    this.setResponseObject(response);
}
Also used : ListResponse(org.apache.cloudstack.api.response.ListResponse) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) ApplicationLoadBalancerRule(org.apache.cloudstack.network.lb.ApplicationLoadBalancerRule) ApplicationLoadBalancerResponse(org.apache.cloudstack.api.response.ApplicationLoadBalancerResponse)

Example 4 with ApplicationLoadBalancerRule

use of org.apache.cloudstack.network.lb.ApplicationLoadBalancerRule in project cloudstack by apache.

the class UpdateApplicationLoadBalancerCmd method execute.

/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
@Override
public void execute() {
    CallContext.current().setEventDetails("Load balancer ID: " + getId());
    ApplicationLoadBalancerRule rule = _appLbService.updateApplicationLoadBalancer(getId(), this.getCustomId(), getDisplay());
    ApplicationLoadBalancerResponse lbResponse = _responseGenerator.createLoadBalancerContainerReponse(rule, _lbService.getLbInstances(getId()));
    setResponseObject(lbResponse);
    lbResponse.setResponseName(getCommandName());
}
Also used : ApplicationLoadBalancerRule(org.apache.cloudstack.network.lb.ApplicationLoadBalancerRule) ApplicationLoadBalancerResponse(org.apache.cloudstack.api.response.ApplicationLoadBalancerResponse)

Aggregations

ApplicationLoadBalancerRule (org.apache.cloudstack.network.lb.ApplicationLoadBalancerRule)4 ApplicationLoadBalancerResponse (org.apache.cloudstack.api.response.ApplicationLoadBalancerResponse)3 InsufficientAddressCapacityException (com.cloud.exception.InsufficientAddressCapacityException)2 InsufficientVirtualNetworkCapacityException (com.cloud.exception.InsufficientVirtualNetworkCapacityException)2 NetworkRuleConflictException (com.cloud.exception.NetworkRuleConflictException)2 ServerApiException (org.apache.cloudstack.api.ServerApiException)2 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)1 ResourceAllocationException (com.cloud.exception.ResourceAllocationException)1 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ListResponse (org.apache.cloudstack.api.response.ListResponse)1