Search in sources :

Example 1 with LoadBalancerResponse

use of com.cloud.api.response.LoadBalancerResponse 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 LoadBalancerResponse

use of com.cloud.api.response.LoadBalancerResponse 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 LoadBalancerResponse

use of com.cloud.api.response.LoadBalancerResponse in project cosmic by MissionCriticalCloud.

the class UpdateLoadBalancerRuleCmd method execute.

@Override
public void execute() {
    CallContext.current().setEventDetails("Load balancer ID: " + getId());
    final LoadBalancer result = _lbService.updateLoadBalancerRule(this);
    if (result != null) {
        final LoadBalancerResponse response = _responseGenerator.createLoadBalancerResponse(result);
        response.setResponseName(getCommandName());
        this.setResponseObject(response);
    } else {
        throw new ServerApiException(ApiErrorCode.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 4 with LoadBalancerResponse

use of com.cloud.api.response.LoadBalancerResponse in project cosmic by MissionCriticalCloud.

the class ListLoadBalancerRulesCmd method execute.

// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////
@Override
public void execute() {
    final Pair<List<? extends LoadBalancer>, Integer> loadBalancers = _lbService.searchForLoadBalancers(this);
    final ListResponse<LoadBalancerResponse> response = new ListResponse<>();
    final List<LoadBalancerResponse> lbResponses = new ArrayList<>();
    if (loadBalancers != null) {
        for (final LoadBalancer loadBalancer : loadBalancers.first()) {
            final 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(com.cloud.api.response.LoadBalancerResponse) ListResponse(com.cloud.api.response.ListResponse) ArrayList(java.util.ArrayList) LoadBalancer(com.cloud.network.rules.LoadBalancer) ArrayList(java.util.ArrayList) List(java.util.List)

Example 5 with LoadBalancerResponse

use of com.cloud.api.response.LoadBalancerResponse in project cosmic by MissionCriticalCloud.

the class CreateLoadBalancerRuleCmd method execute.

@Override
public void execute() throws ResourceAllocationException, ResourceUnavailableException {
    final 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 (final Exception ex) {
        s_logger.warn("Failed to create LB rule due to exception ", ex);
    }
    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(com.cloud.api.response.LoadBalancerResponse) ServerApiException(com.cloud.api.ServerApiException) LoadBalancer(com.cloud.network.rules.LoadBalancer) CallContext(com.cloud.context.CallContext) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) ResourceAllocationException(com.cloud.exception.ResourceAllocationException) ServerApiException(com.cloud.api.ServerApiException) NetworkRuleConflictException(com.cloud.exception.NetworkRuleConflictException) InsufficientAddressCapacityException(com.cloud.exception.InsufficientAddressCapacityException)

Aggregations

LoadBalancerResponse (com.cloud.api.response.LoadBalancerResponse)7 LoadBalancer (com.cloud.network.rules.LoadBalancer)6 ServerApiException (com.cloud.api.ServerApiException)4 ArrayList (java.util.ArrayList)3 ListResponse (com.cloud.api.response.ListResponse)2 InsufficientAddressCapacityException (com.cloud.exception.InsufficientAddressCapacityException)2 NetworkRuleConflictException (com.cloud.exception.NetworkRuleConflictException)2 ResourceAllocationException (com.cloud.exception.ResourceAllocationException)2 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)2 ResourceTagResponse (com.cloud.api.response.ResourceTagResponse)1 CallContext (com.cloud.context.CallContext)1 DataCenter (com.cloud.dc.DataCenter)1 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)1 Network (com.cloud.network.Network)1 PhysicalNetwork (com.cloud.network.PhysicalNetwork)1 IPAddressVO (com.cloud.network.dao.IPAddressVO)1 FirewallRule (com.cloud.network.rules.FirewallRule)1 ResourceTag (com.cloud.server.ResourceTag)1 UserContext (com.cloud.user.UserContext)1 InvalidParameterValueException (com.cloud.utils.exception.InvalidParameterValueException)1