Search in sources :

Example 1 with ApplicationLoadBalancerResponse

use of org.apache.cloudstack.api.response.ApplicationLoadBalancerResponse in project cloudstack by apache.

the class ApiResponseHelper method createLoadBalancerContainerReponse.

@Override
public ApplicationLoadBalancerResponse createLoadBalancerContainerReponse(ApplicationLoadBalancerRule lb, Map<Ip, UserVm> lbInstances) {
    ApplicationLoadBalancerResponse lbResponse = new ApplicationLoadBalancerResponse();
    lbResponse.setId(lb.getUuid());
    lbResponse.setName(lb.getName());
    lbResponse.setDescription(lb.getDescription());
    lbResponse.setAlgorithm(lb.getAlgorithm());
    lbResponse.setForDisplay(lb.isDisplay());
    Network nw = ApiDBUtils.findNetworkById(lb.getNetworkId());
    lbResponse.setNetworkId(nw.getUuid());
    populateOwner(lbResponse, lb);
    if (lb.getScheme() == Scheme.Internal) {
        lbResponse.setSourceIp(lb.getSourceIp().addr());
        //TODO - create the view for the load balancer rule to reflect the network uuid
        Network network = ApiDBUtils.findNetworkById(lb.getNetworkId());
        lbResponse.setSourceIpNetworkId(network.getUuid());
    } else {
        //for public, populate the ip information from the ip address
        IpAddress publicIp = ApiDBUtils.findIpAddressById(lb.getSourceIpAddressId());
        lbResponse.setSourceIp(publicIp.getAddress().addr());
        Network ntwk = ApiDBUtils.findNetworkById(publicIp.getNetworkId());
        lbResponse.setSourceIpNetworkId(ntwk.getUuid());
    }
    //set load balancer rules information (only one rule per load balancer in this release)
    List<ApplicationLoadBalancerRuleResponse> ruleResponses = new ArrayList<ApplicationLoadBalancerRuleResponse>();
    ApplicationLoadBalancerRuleResponse ruleResponse = new ApplicationLoadBalancerRuleResponse();
    ruleResponse.setInstancePort(lb.getDefaultPortStart());
    ruleResponse.setSourcePort(lb.getSourcePortStart());
    FirewallRule.State stateToSet = lb.getState();
    if (stateToSet.equals(FirewallRule.State.Revoke)) {
        stateToSet = FirewallRule.State.Deleting;
    }
    ruleResponse.setState(stateToSet.toString());
    ruleResponse.setObjectName("loadbalancerrule");
    ruleResponses.add(ruleResponse);
    lbResponse.setLbRules(ruleResponses);
    //set Lb instances information
    List<ApplicationLoadBalancerInstanceResponse> instanceResponses = new ArrayList<ApplicationLoadBalancerInstanceResponse>();
    for (Map.Entry<Ip, UserVm> entry : lbInstances.entrySet()) {
        Ip ip = entry.getKey();
        UserVm vm = entry.getValue();
        ApplicationLoadBalancerInstanceResponse instanceResponse = new ApplicationLoadBalancerInstanceResponse();
        instanceResponse.setIpAddress(ip.addr());
        instanceResponse.setId(vm.getUuid());
        instanceResponse.setName(vm.getInstanceName());
        instanceResponse.setObjectName("loadbalancerinstance");
        instanceResponses.add(instanceResponse);
    }
    lbResponse.setLbInstances(instanceResponses);
    //set tag information
    List<? extends ResourceTag> tags = ApiDBUtils.listByResourceTypeAndId(ResourceObjectType.LoadBalancer, lb.getId());
    List<ResourceTagResponse> tagResponses = new ArrayList<ResourceTagResponse>();
    for (ResourceTag tag : tags) {
        ResourceTagResponse tagResponse = createResourceTagResponse(tag, true);
        CollectionUtils.addIgnoreNull(tagResponses, tagResponse);
    }
    lbResponse.setTags(tagResponses);
    lbResponse.setObjectName("loadbalancer");
    return lbResponse;
}
Also used : PortableIp(org.apache.cloudstack.region.PortableIp) NicSecondaryIp(com.cloud.vm.NicSecondaryIp) Ip(com.cloud.utils.net.Ip) ArrayList(java.util.ArrayList) UserVm(com.cloud.uservm.UserVm) ResourceTag(com.cloud.server.ResourceTag) Network(com.cloud.network.Network) PhysicalNetwork(com.cloud.network.PhysicalNetwork) ResourceTagResponse(org.apache.cloudstack.api.response.ResourceTagResponse) IpAddress(com.cloud.network.IpAddress) ApplicationLoadBalancerRuleResponse(org.apache.cloudstack.api.response.ApplicationLoadBalancerRuleResponse) ApplicationLoadBalancerResponse(org.apache.cloudstack.api.response.ApplicationLoadBalancerResponse) FirewallRule(com.cloud.network.rules.FirewallRule) Map(java.util.Map) HashMap(java.util.HashMap) ApplicationLoadBalancerInstanceResponse(org.apache.cloudstack.api.response.ApplicationLoadBalancerInstanceResponse)

Example 2 with ApplicationLoadBalancerResponse

use of org.apache.cloudstack.api.response.ApplicationLoadBalancerResponse 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 ApplicationLoadBalancerResponse

use of org.apache.cloudstack.api.response.ApplicationLoadBalancerResponse 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 ApplicationLoadBalancerResponse

use of org.apache.cloudstack.api.response.ApplicationLoadBalancerResponse 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

ApplicationLoadBalancerResponse (org.apache.cloudstack.api.response.ApplicationLoadBalancerResponse)4 ApplicationLoadBalancerRule (org.apache.cloudstack.network.lb.ApplicationLoadBalancerRule)3 ArrayList (java.util.ArrayList)2 InsufficientAddressCapacityException (com.cloud.exception.InsufficientAddressCapacityException)1 InsufficientVirtualNetworkCapacityException (com.cloud.exception.InsufficientVirtualNetworkCapacityException)1 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)1 NetworkRuleConflictException (com.cloud.exception.NetworkRuleConflictException)1 ResourceAllocationException (com.cloud.exception.ResourceAllocationException)1 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)1 IpAddress (com.cloud.network.IpAddress)1 Network (com.cloud.network.Network)1 PhysicalNetwork (com.cloud.network.PhysicalNetwork)1 FirewallRule (com.cloud.network.rules.FirewallRule)1 ResourceTag (com.cloud.server.ResourceTag)1 UserVm (com.cloud.uservm.UserVm)1 Ip (com.cloud.utils.net.Ip)1 NicSecondaryIp (com.cloud.vm.NicSecondaryIp)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1