Search in sources :

Example 1 with ApplicationLoadBalancerInstanceResponse

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

Aggregations

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 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ApplicationLoadBalancerInstanceResponse (org.apache.cloudstack.api.response.ApplicationLoadBalancerInstanceResponse)1 ApplicationLoadBalancerResponse (org.apache.cloudstack.api.response.ApplicationLoadBalancerResponse)1 ApplicationLoadBalancerRuleResponse (org.apache.cloudstack.api.response.ApplicationLoadBalancerRuleResponse)1 ResourceTagResponse (org.apache.cloudstack.api.response.ResourceTagResponse)1 PortableIp (org.apache.cloudstack.region.PortableIp)1