use of org.apache.cloudstack.api.response.ApplicationLoadBalancerRuleResponse 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;
}
Aggregations